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 ;
19
+ use Doctrine \ORM \Mapping \Embedded ;
18
20
use Doctrine \ORM \Mapping \MappingException as OrmMappingException ;
19
21
use Doctrine \Persistence \Mapping \MappingException ;
20
22
use Symfony \Component \PropertyInfo \PropertyAccessExtractorInterface ;
30
32
class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface
31
33
{
32
34
private $ entityManager ;
33
- private $ classMetadataFactory ;
34
35
35
36
public function __construct (EntityManagerInterface $ entityManager )
36
37
{
@@ -48,7 +49,7 @@ public function getProperties(string $class, array $context = [])
48
49
49
50
$ properties = array_merge ($ metadata ->getFieldNames (), $ metadata ->getAssociationNames ());
50
51
51
- if ($ metadata instanceof ClassMetadataInfo && class_exists (\ Doctrine \ ORM \ Mapping \ Embedded::class) && $ metadata ->embeddedClasses ) {
52
+ if ($ metadata instanceof ClassMetadataInfo && class_exists (Embedded::class) && $ metadata ->embeddedClasses ) {
52
53
$ properties = array_filter ($ properties , function ($ property ) {
53
54
return !str_contains ($ property , '. ' );
54
55
});
@@ -90,7 +91,7 @@ public function getTypes(string $class, string $property, array $context = [])
90
91
91
92
if (isset ($ associationMapping ['indexBy ' ])) {
92
93
/** @var ClassMetadataInfo $subMetadata */
93
- $ subMetadata = $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ associationMapping [ ' targetEntity ' ]) : $ this -> classMetadataFactory -> getMetadataFor ($ associationMapping ['targetEntity ' ]);
94
+ $ subMetadata = $ this ->entityManager -> getClassMetadata ($ associationMapping ['targetEntity ' ]);
94
95
95
96
// Check if indexBy value is a property
96
97
$ fieldName = $ associationMapping ['indexBy ' ];
@@ -103,7 +104,7 @@ public function getTypes(string $class, string $property, array $context = [])
103
104
104
105
/** @var ClassMetadataInfo $subMetadata */
105
106
$ indexProperty = $ subMetadata ->getSingleAssociationReferencedJoinColumnName ($ fieldName );
106
- $ subMetadata = $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ associationMapping [ ' targetEntity ' ]) : $ this -> classMetadataFactory -> getMetadataFor ($ associationMapping ['targetEntity ' ]);
107
+ $ subMetadata = $ this ->entityManager -> getClassMetadata ($ associationMapping ['targetEntity ' ]);
107
108
108
109
//Not a property, maybe a column name?
109
110
if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ indexProperty ))) {
@@ -122,14 +123,14 @@ public function getTypes(string $class, string $property, array $context = [])
122
123
return [new Type (
123
124
Type::BUILTIN_TYPE_OBJECT ,
124
125
false ,
125
- ' Doctrine\Common\Collections\ Collection' ,
126
+ Collection::class ,
126
127
true ,
127
128
new Type ($ collectionKeyType ),
128
129
new Type (Type::BUILTIN_TYPE_OBJECT , false , $ class )
129
130
)];
130
131
}
131
132
132
- if ($ metadata instanceof ClassMetadataInfo && class_exists (\ Doctrine \ ORM \ Mapping \ Embedded::class) && isset ($ metadata ->embeddedClasses [$ property ])) {
133
+ if ($ metadata instanceof ClassMetadataInfo && class_exists (Embedded::class) && isset ($ metadata ->embeddedClasses [$ property ])) {
133
134
return [new Type (Type::BUILTIN_TYPE_OBJECT , false , $ metadata ->embeddedClasses [$ property ]['class ' ])];
134
135
}
135
136
@@ -207,8 +208,8 @@ public function isWritable(string $class, string $property, array $context = [])
207
208
private function getMetadata (string $ class ): ?ClassMetadata
208
209
{
209
210
try {
210
- return $ this ->entityManager ? $ this -> entityManager -> getClassMetadata ( $ class ) : $ this -> classMetadataFactory -> getMetadataFor ($ class );
211
- } catch (MappingException | OrmMappingException $ exception ) {
211
+ return $ this ->entityManager -> getClassMetadata ($ class );
212
+ } catch (MappingException | OrmMappingException $ exception ) {
212
213
return null ;
213
214
}
214
215
}
0 commit comments