8000 Merge branch '4.4' into 5.0 · symfony/symfony@11097a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 11097a5

Browse files
Merge branch '4.4' into 5.0
* 4.4: minor #35833 [FrameworkBundle] Add missing items in the unused tag pass whitelist (fabpot) [HttpClient][DX] Add URL context to JsonException messages [Routing] Improve localized routes performances [4.4][DoctrineBridge] Use new Types::* constants and support new json type [Validator] Add missing translations [Messenger] Use Doctrine DBAL new Types::* constants
2 parents 8b819ba + 1107548 commit 11097a5

File tree

17 files changed

+403
-102
lines changed

17 files changed

+403
-102
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form;
1313

1414
use Doctrine\DBAL\Types\Type;
15+
use Doctrine\DBAL\Types\Types;
1516
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1617
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
1718
use Doctrine\Persistence\ManagerRegistry;
@@ -28,9 +29,15 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
2829

2930
private $cache = [];
3031

32+
private static $useDeprecatedConstants;
33+
3134
public function __construct(ManagerRegistry $registry)
3235
{
3336
$this->registry = $registry;
37+
38+
if (null === self::$useDeprecatedConstants) {
39+
self::$useDeprecatedConstants = !class_exists(Types::class);
40+
}
3441
}
3542

3643
/**
@@ -52,39 +59,39 @@ public function guessType(string $class, string $property)
5259
}
5360

5461
switch ($metadata->getTypeOfField($property)) {
55-
case Type::TARRAY:
56-
case Type::SIMPLE_ARRAY:
62+
case self::$useDeprecatedConstants ? Type::TARRAY : Types::ARRAY:
63+
case self::$useDeprecatedConstants ? Type::SIMPLE_ARRAY : Types::SIMPLE_ARRAY:
5764
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CollectionType', [], Guess::MEDIUM_CONFIDENCE);
58-
case Type::BOOLEAN:
65+
case self::$useDeprecatedConstants ? Type::BOOLEAN : Types::BOOLEAN:
5966
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CheckboxType', [], Guess::HIGH_CONFIDENCE);
60-
case Type::DATETIME:
61-
case Type::DATETIMETZ:
67+
case self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE:
68+
case self::$useDeprecatedConstants ? Type::DATETIMETZ : Types::DATETIMETZ_MUTABLE:
6269
case 'vardatetime':
6370
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE);
6471
case 'datetime_immutable':
6572
case 'datetimetz_immutable':
6673
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE);
6774
case 'dateinterval':
6875
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateIntervalType', [], Guess::HIGH_CONFIDENCE);
69-
case Type::DATE:
76+
case self::$useDeprecatedConstants ? Type::DATE : Types::DATE_MUTABLE:
7077
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::HIGH_CONFIDENCE);
7178
case 'date_immutable':
7279
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE);
73-
case Type::TIME:
80+
case self::$useDeprecatedConstants ? Type::TIME : Types::TIME_MUTABLE:
7481
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', [], Guess::HIGH_CONFIDENCE);
7582
case 'time_immutable':
7683
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE);
77-
case Type::DECIMAL:
84+
case self::$useDeprecatedConstants ? Type::DECIMAL : Types::DECIMAL:
7885
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\NumberType', ['input' => 'string'], Guess::MEDIUM_CONFIDENCE);
79-
case Type::FLOAT:
86+
case self::$useDeprecatedConstants ? Type::FLOAT : Types::FLOAT:
8087
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\NumberType', [], Guess::MEDIUM_CONFIDENCE);
81-
case Type::INTEGER:
82-
case Type::BIGINT:
83-
case Type::SMALLINT:
88+
case self::$useDeprecatedConstants ? Type::INTEGER : Types::INTEGER:
89+
case self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT:
90+
case self::$useDeprecatedConstants ? Type::SMALLINT : Types::SMALLINT:
8491
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\IntegerType', [], Guess::MEDIUM_CONFIDENCE);
85-
case Type::STRING:
92+
case self::$useDeprecatedConstants ? Type::STRING : Types::STRING:
8693
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::MEDIUM_CONFIDENCE);
87-
case Type::TEXT:
94+
case self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT:
8895
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextareaType', [], Guess::MEDIUM_CONFIDENCE);
8996
default:
9097
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE);
@@ -107,7 +114,7 @@ public function guessRequired(string $class, string $property)
107114

108115
// Check whether the field exists and is nullable or not
109116
if (isset($classMetadata->fieldMappings[$property])) {
110-
if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
117+
if (!$classMetadata->isNullable($property) && (self::$useDeprecatedConstants ? Type::BOOLEAN : Types::BOOLEAN) !== $classMetadata->getTypeOfField($property)) {
111118
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
112119
}
113120

@@ -144,7 +151,7 @@ public function guessMaxLength(string $class, string $property)
144151
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
145152
}
146153

147-
if (\in_array($ret[0]->getTypeOfField($property), [Type::DECIMAL, Type::FLOAT])) {
154+
if (\in_array($ret[0]->getTypeOfField($property), self::$useDeprecatedConstants ? [Type::DECIMAL, Type::FLOAT] : [Types::DECIMAL, Types::FLOAT])) {
148155
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
149156
}
150157
}
@@ -159,7 +166,7 @@ public function guessPattern(string $class, string $property)
159166
{
160167
$ret = $this->getMetadata($class);
161168
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
162-
if (\in_array($ret[0]->getTypeOfField($property), [Type::DECIMAL, Type::FLOAT])) {
169+
if (\in_array($ret[0]->getTypeOfField($property), self::$useDeprecatedConstants ? [Type::DECIMAL, Type::FLOAT] : [Types::DECIMAL, Types::FLOAT])) {
163170
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
164171
}
165172
}

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

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\PropertyInfo;
1313

1414
use Doctrine\DBAL\Types\Type as DBALType;
15+
use Doctrine\DBAL\Types\Types;
1516
use Doctrine\ORM\EntityManagerInterface;
1617
use Doctrine\ORM\Mapping\ClassMetadata;
1718
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -31,10 +32,15 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
3132
{
3233
private $entityManager;
3334
private $classMetadataFactory;
35+
private static $useDeprecatedConstants;
3436

3537
public function __construct(EntityManagerInterface $entityManager)
3638
{
3739
$this->entityManager = $entityManager;
40+
41+
if (null === self::$useDeprecatedConstants) {
42+
self::$useDeprecatedConstants = !class_exists(Types::class);
43+
}
3844
}
3945

4046
/**
@@ -135,11 +141,11 @@ public function getTypes(string $class, string $property, array $context = [])
135141
switch ($builtinType) {
136142
case Type::BUILTIN_TYPE_OBJECT:
137143
switch ($typeOfField) {
138-
case DBALType::DATE:
139-
case DBALType::DATETIME:
140-
case DBALType::DATETIMETZ:
144+
case self::$useDeprecatedConstants ? DBALType::DATE : Types::DATE_MUTABLE:
145+
case self::$useDeprecatedConstants ? DBALType::DATETIME : Types::DATETIME_MUTABLE:
146+
case self::$useDeprecatedConstants ? DBALType::DATETIMETZ : Types::DATETIMETZ_MUTABLE:
141147
case 'vardatetime':
142-
case DBALType::TIME:
148+
case self::$useDeprecatedConstants ? DBALType::TIME : Types::TIME_MUTABLE:
143149
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];
144150

145151
case 'date_immutable':
@@ -155,11 +161,12 @@ public function getTypes(string $class, string $property, array $context = [])
155161
break;
156162
case Type::BUILTIN_TYPE_ARRAY:
157163
switch ($typeOfField) {
158-
case DBALType::TARRAY:
159-
case DBALType::JSON_ARRAY:
164+
case self::$useDeprecatedConstants ? DBALType::TARRAY : Types::ARRAY:
165+
case 'json_array':
166+
case self::$useDeprecatedConstants ? false : Types::JSON:
160167
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
161168

162-
case DBALType::SIMPLE_ARRAY:
169+
case self::$useDeprecatedConstants ? DBALType::SIMPLE_ARRAY : Types::SIMPLE_ARRAY:
163170
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
164171
}
165172
}
@@ -234,43 +241,44 @@ private function isAssociationNullable(array $associationMapping): bool
234241
private function getPhpType(string $doctrineType): ?string
235242
{
236243
switch ($doctrineType) {
237-
case DBALType::SMALLINT:
238-
case DBALType::INTEGER:
244+
case self::$useDeprecatedConstants ? DBALType::SMALLINT : Types::SMALLINT:
245+
case self::$useDeprecatedConstants ? DBALType::INTEGER : Types::INTEGER:
239246
return Type::BUILTIN_TYPE_INT;
240247

241-
case DBALType::FLOAT:
248+
case self::$useDeprecatedConstants ? DBALType::FLOAT : Types::FLOAT:
242249
return Type::BUILTIN_TYPE_FLOAT;
243250

244-
case DBALType::BIGINT:
245-
case DBALType::STRING:
246-
case DBALType::TEXT:
247-
case DBALType::GUID:
248-
case DBALType::DECIMAL:
251+
case self::$useDeprecatedConstants ? DBALType::BIGINT : Types::BIGINT:
252+
case self::$useDeprecatedConstants ? DBALType::STRING : Types::STRING:
253+
case self::$useDeprecatedConstants ? DBALType::TEXT : Types::TEXT:
254+
case self::$useDeprecatedConstants ? DBALType::GUID : Types::GUID:
255+
case self::$useDeprecatedConstants ? DBALType::DECIMAL : Types::DECIMAL:
249256
return Type::BUILTIN_TYPE_STRING;
250257

251-
case DBALType::BOOLEAN:
258+
case self::$useDeprecatedConstants ? DBALType::BOOLEAN : Types::BOOLEAN:
252259
return Type::BUILTIN_TYPE_BOOL;
253260

254-
case DBALType::BLOB:
261+
case self::$useDeprecatedConstants ? DBALType::BLOB : Types::BLOB:
255262
case 'binary':
256263
return Type::BUILTIN_TYPE_RESOURCE;
257264

258-
case DBALType::OBJECT:
259-
case DBALType::DATE:
260-
case DBALType::DATETIME:
261-
case DBALType::DATETIMETZ:
265+
case self::$useDeprecatedConstants ? DBALType::OBJECT : Types::OBJECT:
266+
case self::$useDeprecatedConstants ? DBALType::DATE : Types::DATE_MUTABLE:
267+
case self::$useDeprecatedConstants ? DBALType::DATETIME : Types::DATETIME_MUTABLE:
268+
case self::$useDeprecatedConstants ? DBALType::DATETIMETZ : Types::DATETIMETZ_MUTABLE:
262269
case 'vardatetime':
263-
case DBALType::TIME:
270+
case self::$useDeprecatedConstants ? DBALType::TIME : Types::TIME_MUTABLE:
264271
case 'date_immutable':
265272
case 'datetime_immutable':
266273
case 'datetimetz_immutable':
267274
case 'time_immutable':
268275
case 'dateinterval':
269276
return Type::BUILTIN_TYPE_OBJECT;
270277

271-
case DBALType::TARRAY:
272-
case DBALType::SIMPLE_ARRAY:
273-
case DBALType::JSON_ARRAY:
278+
case self::$useDeprecatedConstants ? DBALType::TARRAY : Types::ARRAY:
279+
case self::$useDeprecatedConstants ? DBALType::SIMPLE_ARRAY : Types::SIMPLE_ARRAY:
280+
case 'json_array':
281+
case self::$useDeprecatedConstants ? false : Types::JSON:
274282
return Type::BUILTIN_TYPE_ARRAY;
275283
}
276284

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
namespace Symfony\Bridge\Doctrine\Security\RememberMe;
1313

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\Types\Type as DoctrineType;
15+
use Doctrine\DBAL\Types\Type;
16+
use Doctrine\DBAL\Types\Types;
1617
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
1718
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentTokenInterface;
1819
use Symfony\Component\Security\Core\Authentication\RememberMe\TokenProviderInterface;
@@ -40,9 +41,15 @@ class DoctrineTokenProvider implements TokenProviderInterface
4041
{
4142
private $conn;
4243

44+
private static $useDeprecatedConstants;
45+
4346
public function __construct(Connection $conn)
4447
{
4548
$this->conn = $conn;
49+
50+
if (null === self::$useDeprecatedConstants) {
51+
self::$useDeprecatedConstants = !class_exists(Types::class);
52+
}
4653
}
4754

4855
/**
@@ -90,7 +97,7 @@ public function updateToken(string $series, string $tokenValue, \DateTime $lastU
9097
];
9198
$paramTypes = [
9299
'value' => \PDO::PARAM_STR,
93-
'lastUsed' => DoctrineType::DATETIME,
100+
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
94101
'series' => \PDO::PARAM_STR,
95102
];
96103
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
@@ -119,7 +126,7 @@ public function createNewToken(PersistentTokenInterface $token)
119126
'username' => \PDO::PARAM_STR,
120127
'series' => \PDO::PARAM_STR,
121128
'value' => \PDO::PARAM_STR,
122-
'lastUsed' => DoctrineType::DATETIME,
129+
'lastUsed' => self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
123130
];
124131
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
125132
}

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

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use Doctrine\Common\Collections\Collection;
1515
use Doctrine\DBAL\Types\Type as DBALType;
16+
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\EntityManager;
1718
use Doctrine\ORM\Tools\Setup;
1819
use PHPUnit\Framework\TestCase;
1920
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
21+
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy210;
2022
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineGeneratedValue;
2123
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation;
2224
use Symfony\Component\PropertyInfo\Type;
@@ -41,29 +43,40 @@ private function createExtractor()
4143

4244
public function testGetProperties()
4345
{
46+
// Fields
47+
$expected = [
48+
'id',
49+
'guid',
50+
'time',
51+
'timeImmutable',
52+
'dateInterval',
53+
'jsonArray',
54+
'simpleArray',
55+
'float',
56+
'decimal',
57+
'bool',
58+
'binary',
59+
'customFoo',
60+
'bigint',
61+
];
62+
63+
if (class_exists(Types::class)) {
64+
$expected[] = 'json';
65+
}
66+
67+
// Associations
68+
$expected = array_merge($expected, [
69+
'foo',
70+
'bar',
71+
'indexedBar',
72+
'indexedFoo',
73+
'indexedByDt',
74+
'indexedByCustomType',
75+
]);
76+
4477
$this->assertEquals(
45-
[
46-
'id',
47-
'guid',
48-
'time',
49-
'timeImmutable',
50-
'dateInterval',
51-
'json',
52-
'simpleArray',
53-
'float',
54-
'decimal',
55-
'bool',
56-
'binary',
57-
'customFoo',
58-
'bigint',
59-
'foo',
60-
'bar',
61-
'indexedBar',
62-
'indexedFoo',
63-
'indexedByDt',
64-
'indexedByCustomType',
65-
],
66-
$this->createExtractor()->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
78+
$expected,
79+
$this->createExtractor()->getProperties(!class_exists(Types::class) ? 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy' : DoctrineDummy210::class)
6780
);
6881
}
6982

@@ -87,7 +100,7 @@ public function testTestGetPropertiesWithEmbedded()
87100
*/
88101
public function testExtract($property, array $type = null)
89102
{
90-
$this->assertEquals($type, $this->createExtractor()->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, []));
103+
$this->assertEquals($type, $this->createExtractor()->getTypes(!class_exists(Types::class) ? 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy' : DoctrineDummy210::class, $property, []));
91104
}
92105

93106
public function testExtractWithEmbedded()
@@ -113,7 +126,7 @@ public function testExtractWithEmbedded()
113126

114127
public function typesProvider()
115128
{
116-
return [
129+
$provider = [
117130
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
118131
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
119132
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
@@ -124,7 +137,7 @@ public function typesProvider()
124137
['decimal', [new Type(Type::BUILTIN_TYPE_STRING)]],
125138
['bool', [new Type(Type::BUILTIN_TYPE_BOOL)]],
126139
['binary', [new Type(Type::BUILTIN_TYPE_RESOURCE)]],
127-
['json', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
140+
['jsonArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
128141
['foo', [new Type(Type::BUILTIN_TYPE_OBJECT, true, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')]],
129142
['bar', [new Type(
130143
Type::BUILTIN_TYPE_OBJECT,
@@ -163,6 +176,12 @@ public function typesProvider()
163176
)]],
164177
['indexedByCustomType', null],
165178
];
179+
180+
if (class_exists(Types::class)) {
181+
$provider[] = ['json', [new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)]];
182+
}
183+
184+
return $provider;
166185
}
167186

168187
public function testGetPropertiesCatchException()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DoctrineDummy
7474
/**
7575
* @Column(type="json_array")
7676
*/
77-
private $json;
77+
private $jsonArray;
7878

7979
/**
8080
* @Column(type="simple_array")

0 commit comments

Comments
 (0)
0