Skip to content

Commit 356ab8b

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [ExpressionLanguage] Fixed collisions of character operators with object properties [Validator] Remove specific check for Valid targets [PhpUnitBridge] Use trait instead of extending deprecated class fix remember me Use strict assertion in asset tests [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types Do not rely on the current locale when dumping a Graphviz object fix typo [Ldap] force default network timeout [Config] don't throw on missing excluded paths Docs: Typo, grammar [Validator] Add the missing translations for the Polish ("pl") locale [Console] Inline exact-match handling with 4.4 Set previous exception when rethrown from controller resolver [VarDumper] fixed DateCaster not displaying additional fields [HttpKernel] fix registering DebugHandlersListener regardless of the PHP_SAPI
2 parents bceef1a + 6ae3e77 commit 356ab8b

File tree

4 files changed

+85
-28
lines changed

4 files changed

+85
-28
lines changed

PropertyInfo/DoctrineExtractor.php

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ public function getTypes($class, $property, array $context = [])
114114
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
115115
}
116116

117-
$collectionKeyType = $this->getPhpType($typeOfField);
117+
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
118+
return null;
119+
}
118120
}
119121
}
120122

@@ -134,39 +136,46 @@ public function getTypes($class, $property, array $context = [])
134136

135137
if ($metadata->hasField($property)) {
136138
$typeOfField = $metadata->getTypeOfField($property);
137-
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);
138-
139-
switch ($typeOfField) {
140-
case DBALType::DATE:
141-
case DBALType::DATETIME:
142-
case DBALType::DATETIMETZ:
143-
case 'vardatetime':
144-
case DBALType::TIME:
145-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];
146139

147-
case 'date_immutable':
148-
case 'datetime_immutable':
149-
case 'datetimetz_immutable':
150-
case 'time_immutable':
151-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];
152-
153-
case 'dateinterval':
154-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];
155-
156-
case DBALType::TARRAY:
157-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
140+
if (!$builtinType = $this->getPhpType($typeOfField)) {
141+
return null;
142+
}
158143

159-
case DBALType::SIMPLE_ARRAY:
160-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
144+
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);
161145

162-
case DBALType::JSON_ARRAY:
163-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
146+
switch ($builtinType) {
147+
case Type::BUILTIN_TYPE_OBJECT:
148+
switch ($typeOfField) {
149+
case DBALType::DATE:
150+
case DBALType::DATETIME:
151+
case DBALType::DATETIMETZ:
152+
case 'vardatetime':
153+
case DBALType::TIME:
154+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];
155+
156+
case 'date_immutable':
157+
case 'datetime_immutable':
158+
case 'datetimetz_immutable':
159+
case 'time_immutable':
160+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];
161+
162+
case 'dateinterval':
163+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];
164+
}
164165

165-
default:
166-
$builtinType = $this->getPhpType($typeOfField);
166+
break;
167+
case Type::BUILTIN_TYPE_ARRAY:
168+
switch ($typeOfField) {
169+
case DBALType::TARRAY:
170+
case DBALType::JSON_ARRAY:
171+
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
167172

168-
return $builtinType ? [new Type($builtinType, $nullable)] : null;
173+
case DBALType::SIMPLE_ARRAY:
174+
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
175+
}
169176
}
177+
178+
return [new Type($builtinType, $nullable)];
170179
}
171180

172181
return null;
@@ -258,7 +267,22 @@ private function getPhpType(string $doctrineType): ?string
258267
return Type::BUILTIN_TYPE_RESOURCE;
259268

260269
case DBALType::OBJECT:
270+
case DBALType::DATE:
271+
case DBALType::DATETIME:
272+
case DBALType::DATETIMETZ:
273+
case 'vardatetime':
274+
case DBALType::TIME:
275+
case 'date_immutable':
276+
case 'datetime_immutable':
277+
case 'datetimetz_immutable':
278+
case 'time_immutable':
279+
case 'dateinterval':
261280
return Type::BUILTIN_TYPE_OBJECT;
281+
282+
case DBALType::TARRAY:
283+
case DBALType::SIMPLE_ARRAY:
284+
case DBALType::JSON_ARRAY:
285+
return Type::BUILTIN_TYPE_ARRAY;
262286
}
263287

264288
return null;

Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo;
1313

14+
use Doctrine\Common\Collections\Collection;
1415
use Doctrine\DBAL\Types\Type as DBALType;
1516
use Doctrine\ORM\EntityManager;
1617
use Doctrine\ORM\Tools\Setup;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
1920
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineGeneratedValue;
21+
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation;
2022
use Symfony\Component\PropertyInfo\Type;
2123

2224
/**
@@ -68,6 +70,8 @@ private function doTestGetProperties(bool $legacy)
6870
'bar',
6971
'indexedBar',
7072
'indexedFoo',
73+
'indexedByDt',
74+
'indexedByCustomType',
7175
],
7276
$this->createExtractor($legacy)->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
7377
);
@@ -192,6 +196,15 @@ public function typesProvider()
192196
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
193197
['customFoo', null],
194198
['notMapped', null],
199+
['indexedByDt', [new Type(
200+
Type::BUILTIN_TYPE_OBJECT,
201+
false,
202+
Collection::class,
203+
true,
204+
new Type(Type::BUILTIN_TYPE_OBJECT),
205+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
206+
)]],
207+
['indexedByCustomType', null],
195208
];
196209
}
197210

Tests/PropertyInfo/Fixtures/DoctrineDummy.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,14 @@ class DoctrineDummy
112112
private $bigint;
113113

114114
public $notMapped;
115+
116+
/**
117+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="dt", indexBy="dt")
118+
*/
119+
protected $indexedByDt;
120+
121+
/**
122+
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="customType", indexBy="customType")
123+
*/
124+
private $indexedByCustomType;
115125
}

Tests/PropertyInfo/Fixtures/DoctrineRelation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ class DoctrineRelation
3939
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
4040
*/
4141
protected $foo;
42+
43+
/**
44+
* @Column(type="datetime")
45+
*/
46+
private $dt;
47+
48+
/**
49+
* @Column(type="foo")
50+
*/
51+
private $customType;
4252
}

0 commit comments

Comments
 (0)