11
11
12
12
namespace Symfony \Bridge \Doctrine \PropertyInfo ;
13
13
14
+ use Doctrine \Common \Collections \Collection ;
14
15
use Doctrine \DBAL \Types \Types ;
15
16
use Doctrine \ORM \EntityManagerInterface ;
16
17
use Doctrine \ORM \Mapping \ClassMetadata ;
17
18
use Doctrine \ORM \Mapping \ClassMetadataInfo ;
18
19
use Doctrine \ORM \Mapping \Embedded ;
19
20
use Doctrine \ORM \Mapping \MappingException as OrmMappingException ;
20
- use Doctrine \Persistence \Mapping \ClassMetadataFactory ;
21
21
use Doctrine \Persistence \Mapping \MappingException ;
22
22
use Symfony \Component \PropertyInfo \PropertyAccessExtractorInterface ;
23
23
use Symfony \Component \PropertyInfo \PropertyListExtractorInterface ;
32
32
class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface
33
33
{
34
34
private EntityManagerInterface $ entityManager ;
35
- private ClassMetadataFactory $ classMetadataFactory ;
36
35
37
36
public function __construct (EntityManagerInterface $ entityManager )
38
37
{
@@ -92,7 +91,7 @@ public function getTypes(string $class, string $property, array $context = []):
92
91
93
92
if (isset ($ associationMapping ['indexBy ' ])) {
94
93
/** @var ClassMetadataInfo $subMetadata */
95
- $ subMetadata = $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ associationMapping [ ' targetEntity ' ]) : $ this -> classMetadataFactory -> getMetadataFor ($ associationMapping ['targetEntity ' ]);
94
+ $ subMetadata = $ this ->entityManager -> getClassMetadata ($ associationMapping ['targetEntity ' ]);
96
95
97
96
// Check if indexBy value is a property
98
97
$ fieldName = $ associationMapping ['indexBy ' ];
@@ -105,7 +104,7 @@ public function getTypes(string $class, string $property, array $context = []):
105
104
106
105
/** @var ClassMetadataInfo $subMetadata */
107
106
$ indexProperty = $ subMetadata ->getSingleAssociationReferencedJoinColumnName ($ fieldName );
108
- $ subMetadata = $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ associationMapping [ ' targetEntity ' ]) : $ this -> classMetadataFactory -> getMetadataFor ($ associationMapping ['targetEntity ' ]);
107
+ $ subMetadata = $ this ->entityManager -> getClassMetadata ($ associationMapping ['targetEntity ' ]);
109
108
110
109
//Not a property, maybe a column name?
111
110
if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ indexProperty ))) {
@@ -124,7 +123,7 @@ public function getTypes(string $class, string $property, array $context = []):
124
123
return [new Type (
125
124
Type::BUILTIN_TYPE_OBJECT ,
126
125
false ,
127
- ' Doctrine\Common\Collections\ Collection' ,
126
+ Collection::class ,
128
127
true ,
129
128
new Type ($ collectionKeyType ),
130
129
new Type (Type::BUILTIN_TYPE_OBJECT , false , $ class )
@@ -209,8 +208,8 @@ public function isWritable(string $class, string $property, array $context = [])
209
208
private function getMetadata (string $ class ): ?ClassMetadata
210
209
{
211
210
try {
212
- return $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ class ) : $ this -> classMetadataFactory -> getMetadataFor ($ class );
213
- } catch (MappingException | OrmMappingException $ exception ) {
211
+ return $ this ->entityManager -> getClassMetadata ($ class );
212
+ } catch (MappingException | OrmMappingException $ exception ) {
214
213
return null ;
215
214
}
216
215
}
0 commit comments