Merge branch '5.1' into 5.2

* 5.1:
  [Security] Replace message data in JSON security error response
  [DI] Skip deprecated definitions in CheckTypeDeclarationsPass
  [Messenger][AmazonSqs] Fix auto-setup for fifo queue
  [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
This commit is contained in:
Robin Chalas 2021-01-17 11:58:44 +01:00
commit c702c47f54
10 changed files with 73 additions and 5 deletions

View File

@ -104,7 +104,12 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
/** @var ClassMetadataInfo $subMetadata */
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
//Not a property, maybe a column name?
if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
$fieldName = $subMetadata->getFieldForColumn($indexProperty);
$typeOfField = $subMetadata->getTypeOfField($fieldName);
}
}
}

View File

@ -71,6 +71,7 @@ class DoctrineExtractorTest extends TestCase
'indexedByDt',
'indexedByCustomType',
'indexedBuz',
'dummyGeneratedValueList',
]);
$this->assertEquals(
@ -198,6 +199,14 @@ class DoctrineExtractorTest extends TestCase
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
)]],
['dummyGeneratedValueList', [new Type(
Type::BUILTIN_TYPE_OBJECT,
false,
'Doctrine\Common\Collections\Collection',
true,
new Type(Type::BUILTIN_TYPE_INT),
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
)]],
['json', null],
];

View File

@ -142,4 +142,9 @@ class DoctrineDummy
* @Column(type="json", nullable=true)
*/
private $json;
/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dummyRelation", indexBy="gen_value_col_id", orphanRemoval=true)
*/
protected $dummyGeneratedValueList;
}

View File

@ -15,6 +15,7 @@ use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
@ -34,4 +35,15 @@ class DoctrineGeneratedValue
* @Column
*/
public $foo;
/**
* @var int
* @Column(type="integer", name="gen_value_col_id")
*/
public $valueId;
/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="generatedValueRelation", indexBy="rguid_column", orphanRemoval=true)
*/
protected $relationList;
}

View File

@ -15,6 +15,7 @@ use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\JoinColumn;
/**
* @Entity
@ -60,4 +61,15 @@ class DoctrineRelation
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBuz")
*/
protected $buzField;
/**
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="dummyGeneratedValueList")
*/
private $dummyRelation;
/**
* @ManyToOne(targetEntity="DoctrineGeneratedValue", inversedBy="relationList")
* @JoinColumn(name="gen_value_col_id", referencedColumnName="gen_value_col_id")
*/
private $generatedValueRelation;
}

View File

@ -84,7 +84,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return $value;
}
if (!$value instanceof Definition || $value->hasErrors()) {
if (!$value instanceof Definition || $value->hasErrors() || $value->isDeprecated()) {
return parent::processValue($value, $isRoot);
}

View File

@ -24,6 +24,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPa
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Deprecated;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
@ -720,6 +721,19 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->addToAssertionCount(1);
}
public function testProcessSkipsDeprecatedDefinitions()
{
$container = new ContainerBuilder();
$container
->register('foobar', Deprecated::class)
->setDeprecated(true)
;
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
}
public function testProcessHandleClosureForCallable()
{
$closureDefinition = new Definition(\Closure::class);

View File

@ -0,0 +1,9 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
trigger_deprecation('foo/bar', '1.2.3', 'Deprecated class.');
class Deprecated
{
}

View File

@ -270,7 +270,9 @@ class Connection
$parameters = ['QueueName' => $this->configuration['queue_name']];
if (self::isFifoQueue($this->configuration['queue_name'])) {
$parameters['FifoQueue'] = true;
$parameters['Attributes'] = [
'FifoQueue' => 'true',
];
}
$this->client->createQueue($parameters);

View File

@ -188,10 +188,10 @@ class UsernamePasswordJsonAuthenticationListener extends AbstractListener
}
if (!$this->failureHandler) {
$errorMessage = $failed->getMessageKey();
if (null !== $this->translator) {
$errorMessage = $this->translator->trans($failed->getMessageKey(), $failed->getMessageData(), 'security');
} else {
$errorMessage = strtr($failed->getMessageKey(), $failed->getMessageData());
}
return new JsonResponse(['error' => $errorMessage], 401);