Skip to content

Commit f2c5f25

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [Security] Replace message data in JSON security error response [DI] Skip deprecated definitions in CheckTypeDeclarationsPass [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity
2 parents 402a800 + 5ba237a commit f2c5f25

File tree

9 files changed

+72
-3
lines changed

9 files changed

+72
-3
lines changed

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ public function getTypes(string $class, string $property, array $context = [])
110110
/** @var ClassMetadataInfo $subMetadata */
111111
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
112112
$subMetadata = $this->entityManager ? $this->entityManager->getClassMetadata($associationMapping['targetEntity']) : $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
113-
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
113+
114+
//Not a property, maybe a column name?
115+
if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
116+
$fieldName = $subMetadata->getFieldForColumn($indexProperty);
117+
$typeOfField = $subMetadata->getTypeOfField($fieldName);
118+
}
114119
}
115120
}
116121

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testGetProperties()
7575
'indexedByDt',
7676
'indexedByCustomType',
7777
'indexedBuz',
78+
'dummyGeneratedValueList',
7879
]);
7980

8081
$this->assertEquals(
@@ -202,6 +203,15 @@ public function typesProvider()
202203
new Type(Type::BUILTIN_TYPE_STRING),
203204
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
204205
)]],
206+
['dummyGeneratedValueList', [new Type(
207+
Type::BUILTIN_TYPE_OBJECT,
208+
false,
209+
'Doctrine\Common\Collections\Collection',
210+
true,
211+
new Type(Type::BUILTIN_TYPE_INT),
212+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
213+
)]],
214+
['json', null],
205215
];
206216

207217
if (class_exists(Types::class)) {

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ class DoctrineDummy
137137
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="buzField", indexBy="buzField")
138138
*/
139139
protected $indexedBuz;
140+
141+
/**
142+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dummyRelation", indexBy="gen_value_col_id", orphanRemoval=true)
143+
*/
144+
protected $dummyGeneratedValueList;
140145
}

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineGeneratedValue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\GeneratedValue;
1717
use Doctrine\ORM\Mapping\Id;
18+
use Doctrine\ORM\Mapping\OneToMany;
1819

1920
/**
2021
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -34,4 +35,15 @@ class DoctrineGeneratedValue
3435
* @Column
3536
*/
3637
public $foo;
38+
39+
/**
40+
* @var int
41+
* @Column(type="integer", name="gen_value_col_id")
42+
*/
43+
public $valueId;
44+
45+
/**
46+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="generatedValueRelation", indexBy="rguid_column", orphanRemoval=true)
47+
*/
48+
protected $relationList;
3749
}

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineRelation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\ORM\Mapping\Entity;
1616
use Doctrine\ORM\Mapping\Id;
1717
use Doctrine\ORM\Mapping\ManyToOne;
18+
use Doctrine\ORM\Mapping\JoinColumn;
1819

1920
/**
2021
* @Entity
@@ -60,4 +61,15 @@ class DoctrineRelation
6061
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedBuz")
6162
*/
6263
protected $buzField;
64+
65+
/**
66+
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="dummyGeneratedValueList")
67+
*/
68+
private $dummyRelation;
69+
70+
/**
71+
* @ManyToOne(targetEntity="DoctrineGeneratedValue", inversedBy="relationList")
72+
* @JoinColumn(name="gen_value_col_id", referencedColumnName="gen_value_col_id")
73+
*/
74+
private $generatedValueRelation;
6375
}

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function processValue($value, $isRoot = false)
8484
return $value;
8585
}
8686

87-
if (!$value instanceof Definition || $value->hasErrors()) {
87+
if (!$value instanceof Definition || $value->hasErrors() || $value->isDeprecated()) {
8888
return parent::processValue($value, $isRoot);
8989
}
9090

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
2525
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
2626
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
27+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Deprecated;
2728
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
2829
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
2930
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
@@ -720,6 +721,19 @@ public function testProcessSkipSkippedIds()
720721
$this->addToAssertionCount(1);
721722
}
722723

724+
public function testProcessSkipsDeprecatedDefinitions()
725+
{
726+
$container = new ContainerBuilder();
727+
$container
728+
->register('foobar', Deprecated::class)
729+
->setDeprecated(true)
730+
;
731+
732+
(new CheckTypeDeclarationsPass(true))->process($container);
733+
734+
$this->addToAssertionCount(1);
735+
}
736+
723737
public function testProcessHandleClosureForCallable()
724738
{
725739
$closureDefinition = new Definition(\Closure::class);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
trigger_deprecation('foo/bar', '1.2.3', 'Deprecated class.');
6+
7+
class Deprecated
8+
{
9+
}

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ private function onFailure(Request $request, AuthenticationException $failed): R
182182
}
183183

184184
if (!$this->failureHandler) {
185-
return new JsonResponse(['error' => $failed->getMessageKey()], 401);
185+
$errorMessage = strtr($failed->getMessageKey(), $failed->getMessageData());
186+
187+
return new JsonResponse(['error' => $errorMessage], 401);
186188
}
187189

188190
$response = $this->failureHandler->onAuthenticationFailure($request, $failed);

0 commit comments

Comments
 (0)