Skip to content

Commit bd21865

Browse files
Merge branch '4.4' into 5.0
* 4.4: (25 commits) [DoctrineBridge] Use new Types::* constants and support new json type [Debug][ErrorHandler] improved deprecation notices for methods new args and return type [BrowserKit] Nested file array prevents uploading file [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 versioned namespace clears 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 [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662 [Routing] Add locale requirement for localized routes [Console] Inline exact-match handling with 4.4 Set previous exception when rethrown from controller resolver ...
2 parents 330b610 + 2de5897 commit bd21865

File tree

8 files changed

+122
-28
lines changed

8 files changed

+122
-28
lines changed

Form/Type/DoctrineType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,5 @@ public function reset()
277277
$this->choiceLoaders = [];
278278
}
279279
}
280+
281+
interface_exists(ObjectManager::class);

Form/Type/EntityType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ private function parameterToArray(Parameter $parameter): array
9696
return [$parameter->getName(), $parameter->getType(), $parameter->getValue()];
9797
}
9898
}
99+
100+
interface_exists(ObjectManager::class);

PropertyInfo/DoctrineExtractor.php

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

106-
$collectionKeyType = $this->getPhpType($typeOfField);
106+
if (!$collectionKeyType = $this->getPhpType($typeOfField)) {
107+
return null;
108+
}
107109
}
108110
}
109111

@@ -123,39 +125,46 @@ public function getTypes(string $class, string $property, array $context = [])
123125

124126
if ($metadata->hasField($property)) {
125127
$typeOfField = $metadata->getTypeOfField($property);
126-
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);
127-
128-
switch ($typeOfField) {
129-
case DBALType::DATE:
130-
case DBALType::DATETIME:
131-
case DBALType::DATETIMETZ:
132-
case 'vardatetime':
133-
case DBALType::TIME:
134-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];
135128

136-
case 'date_immutable':
137-
case 'datetime_immutable':
138-
case 'datetimetz_immutable':
139-
case 'time_immutable':
140-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];
141-
142-
case 'dateinterval':
143-
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];
144-
145-
case DBALType::TARRAY:
146-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
129+
if (!$builtinType = $this->getPhpType($typeOfField)) {
130+
return null;
131+
}
147132

148-
case DBALType::SIMPLE_ARRAY:
149-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
133+
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);
150134

151-
case DBALType::JSON_ARRAY:
152-
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
135+
switch ($builtinType) {
136+
case Type::BUILTIN_TYPE_OBJECT:
137+
switch ($typeOfField) {
138+
case DBALType::DATE:
139+
case DBALType::DATETIME:
140+
case DBALType::DATETIMETZ:
141+
case 'vardatetime':
142+
case DBALType::TIME:
143+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')];
144+
145+
case 'date_immutable':
146+
case 'datetime_immutable':
147+
case 'datetimetz_immutable':
148+
case 'time_immutable':
149+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')];
150+
151+
case 'dateinterval':
152+
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')];
153+
}
153154

154-
default:
155-
$builtinType = $this->getPhpType($typeOfField);
155+
break;
156+
case Type::BUILTIN_TYPE_ARRAY:
157+
switch ($typeOfField) {
158+
case DBALType::TARRAY:
159+
case DBALType::JSON_ARRAY:
160+
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];
156161

157-
return $builtinType ? [new Type($builtinType, $nullable)] : null;
162+
case DBALType::SIMPLE_ARRAY:
163+
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))];
164+
}
158165
}
166+
167+
return [new Type($builtinType, $nullable)];
159168
}
160169

161170
return null;
@@ -247,7 +256,22 @@ private function getPhpType(string $doctrineType): ?string
247256
return Type::BUILTIN_TYPE_RESOURCE;
248257

249258
case DBALType::OBJECT:
259+
case DBALType::DATE:
260+
case DBALType::DATETIME:
261+
case DBALType::DATETIMETZ:
262+
case 'vardatetime':
263+
case DBALType::TIME:
264+
case 'date_immutable':
265+
case 'datetime_immutable':
266+
case 'datetimetz_immutable':
267+
case 'time_immutable':
268+
case 'dateinterval':
250269
return Type::BUILTIN_TYPE_OBJECT;
270+
271+
case DBALType::TARRAY:
272+
case DBALType::SIMPLE_ARRAY:
273+
case DBALType::JSON_ARRAY:
274+
return Type::BUILTIN_TYPE_ARRAY;
251275
}
252276

253277
return null;

Security/User/EntityUserProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ private function getClassMetadata(): ClassMetadata
153153
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
154154
}
155155
}
156+
157+
interface_exists(ObjectManager::class);
158+
interface_exists(ObjectRepository::class);

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
/**
@@ -58,6 +60,8 @@ public function testGetProperties()
5860
'bar',
5961
'indexedBar',
6062
'indexedFoo',
63+
'indexedByDt',
64+
'indexedByCustomType',
6165
],
6266
$this->createExtractor()->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
6367
);
@@ -149,6 +153,15 @@ public function typesProvider()
149153
['simpleArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
150154
['customFoo', null],
151155
['notMapped', null],
156+
['indexedByDt', [new Type(
157+
Type::BUILTIN_TYPE_OBJECT,
158+
false,
159+
Collection::class,
160+
true,
161+
new Type(Type::BUILTIN_TYPE_OBJECT),
162+
new Type(Type::BUILTIN_TYPE_OBJECT, false, DoctrineRelation::class)
163+
)]],
164+
['indexedByCustomType', null],
152165
];
153166
}
154167

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
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
use Doctrine\ORM\Mapping\ManyToMany;
18+
use Doctrine\ORM\Mapping\ManyToOne;
19+
use Doctrine\ORM\Mapping\OneToMany;
20+
21+
/**
22+
* @Entity
23+
*/
24+
final class DoctrineDummy210 extends DoctrineDummy
25+
{
26+
/**
27+
* @Column(type="json", nullable=true)
28+
*/
29+
private $json;
30+
}

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)