21
21
use Symfony \Component \PropertyInfo \PropertyAccessExtractorInterface ;
22
22
use Symfony \Component \PropertyInfo \PropertyListExtractorInterface ;
23
23
use Symfony \Component \PropertyInfo \PropertyTypeExtractorInterface ;
24
- use Symfony \Component \PropertyInfo \Type ;
24
+ use Symfony \Component \PropertyInfo \Util \BackwardCompatibilityHelper ;
25
+ use Symfony \Component \TypeInfo \Type ;
26
+ use Symfony \Component \TypeInfo \TypeIdentifier ;
25
27
26
28
/**
27
29
* Extracts data using Doctrine ORM and ODM metadata.
@@ -52,7 +54,7 @@ public function getProperties(string $class, array $context = []): ?array
52
54
return $ properties ;
53
55
}
54
56
55
- public function getTypes (string $ class , string $ property , array $ context = []): ?array
57
+ public function getType (string $ class , string $ property , array $ context = []): ?Type
56
58
{
57
59
if (null === $ metadata = $ this ->getMetadata ($ class )) {
58
60
return null ;
@@ -64,16 +66,17 @@ public function getTypes(string $class, string $property, array $context = []):
64
66
if ($ metadata ->isSingleValuedAssociation ($ property )) {
65
67
if ($ metadata instanceof ClassMetadata) {
66
68
$ associationMapping = $ metadata ->getAssociationMapping ($ property );
67
-
68
69
$ nullable = $ this ->isAssociationNullable ($ associationMapping );
69
70
} else {
70
71
$ nullable = false ;
71
72
}
72
73
73
- return [new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , $ class )];
74
+ $ t = Type::object ($ class );
75
+
76
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
74
77
}
75
78
76
- $ collectionKeyType = Type:: BUILTIN_TYPE_INT ;
79
+ $ collectionKeyType = TypeIdentifier:: INT ;
77
80
78
81
if ($ metadata instanceof ClassMetadata) {
79
82
$ associationMapping = $ metadata ->getAssociationMapping ($ property );
@@ -107,18 +110,11 @@ public function getTypes(string $class, string $property, array $context = []):
107
110
}
108
111
}
109
112
110
- return [new Type (
111
- Type::BUILTIN_TYPE_OBJECT ,
112
- false ,
113
- Collection::class,
114
- true ,
115
- new Type ($ collectionKeyType ),
116
- new Type (Type::BUILTIN_TYPE_OBJECT , false , $ class )
117
- )];
113
+ return Type::collection (Type::object (Collection::class), Type::object ($ class ), Type::builtin ($ collectionKeyType ));
118
114
}
119
115
120
116
if ($ metadata instanceof ClassMetadata && isset ($ metadata ->embeddedClasses [$ property ])) {
121
- return [ new Type (Type:: BUILTIN_TYPE_OBJECT , false , $ metadata ->embeddedClasses [$ property ]['class ' ])] ;
117
+ return Type:: object ( $ metadata ->embeddedClasses [$ property ]['class ' ]);
122
118
}
123
119
124
120
if ($ metadata ->hasField ($ property )) {
@@ -130,32 +126,40 @@ public function getTypes(string $class, string $property, array $context = []):
130
126
131
127
$ nullable = $ metadata instanceof ClassMetadata && $ metadata ->isNullable ($ property );
132
128
$ enumType = null ;
129
+
133
130
if (null !== $ enumClass = $ metadata ->getFieldMapping ($ property )['enumType ' ] ?? null ) {
134
- $ enumType = new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , $ enumClass );
131
+ $ enumType = Type::enum ($ enumClass );
132
+ $ enumType = $ nullable ? Type::nullable ($ enumType ) : $ enumType ;
135
133
}
136
134
137
135
switch ($ builtinType ) {
138
- case Type:: BUILTIN_TYPE_OBJECT :
136
+ case TypeIdentifier:: OBJECT :
139
137
switch ($ typeOfField ) {
140
138
case Types::DATE_MUTABLE :
141
139
case Types::DATETIME_MUTABLE :
142
140
case Types::DATETIMETZ_MUTABLE :
143
141
case 'vardatetime ' :
144
142
case Types::TIME_MUTABLE :
145
- return [new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , 'DateTime ' )];
143
+ $ t = Type::object (\DateTime::class);
144
+
145
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
146
146
147
147
case Types::DATE_IMMUTABLE :
148
148
case Types::DATETIME_IMMUTABLE :
149
149
case Types::DATETIMETZ_IMMUTABLE :
150
150
case Types::TIME_IMMUTABLE :
151
- return [new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , 'DateTimeImmutable ' )];
151
+ $ t = Type::object (\DateTimeImmutable::class);
152
+
153
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
152
154
153
155
case Types::DATEINTERVAL :
154
- return [new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , 'DateInterval ' )];
156
+ $ t = Type::object (\DateInterval::class);
157
+
158
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
155
159
}
156
160
157
161
break ;
158
- case Type:: BUILTIN_TYPE_ARRAY :
162
+ case TypeIdentifier:: ARRAY :
159
163
switch ($ typeOfField ) {
160
164
case 'array ' : // DBAL < 4
161
165
case 'json_array ' : // DBAL < 3
@@ -164,26 +168,39 @@ public function getTypes(string $class, string $property, array $context = []):
164
168
return null ;
165
169
}
166
170
167
- return [new Type (Type::BUILTIN_TYPE_ARRAY , $ nullable , null , true )];
171
+ $ t = Type::array ();
172
+
173
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
168
174
169
175
case Types::SIMPLE_ARRAY :
170
- return [new Type (Type::BUILTIN_TYPE_ARRAY , $ nullable , null , true , new Type (Type::BUILTIN_TYPE_INT ), $ enumType ?? new Type (Type::BUILTIN_TYPE_STRING ))];
176
+ $ t = Type::list ($ enumType ?? Type::string ());
177
+
178
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
171
179
}
172
180
break ;
173
- case Type:: BUILTIN_TYPE_INT :
174
- case Type:: BUILTIN_TYPE_STRING :
181
+ case TypeIdentifier:: INT :
182
+ case TypeIdentifier:: STRING :
175
183
if ($ enumType ) {
176
- return [ $ enumType] ;
184
+ return $ enumType ;
177
185
}
178
186
break ;
179
187
}
180
188
181
- return [new Type ($ builtinType , $ nullable )];
189
+ $ t = Type::builtin ($ builtinType );
190
+
191
+ return $ nullable ? Type::nullable ($ t ) : $ t ;
182
192
}
183
193
184
194
return null ;
185
195
}
186
196
197
+ public function getTypes (string $ class , string $ property , array $ context = []): ?array
198
+ {
199
+ trigger_deprecation ('symfony/doctrine-bridge ' , '7.1 ' , 'The "%s()" method is deprecated, use "%s::getType()" instead. ' , __METHOD__ , self ::class);
200
+
201
+ return BackwardCompatibilityHelper::convertTypeToLegacyTypes ($ this ->getType ($ class , $ property , $ context , true ));
202
+ }
203
+
187
204
public function isReadable (string $ class , string $ property , array $ context = []): ?bool
188
205
{
189
206
return null ;
@@ -241,20 +258,20 @@ private function isAssociationNullable(array|AssociationMapping $associationMapp
241
258
/**
242
259
* Gets the corresponding built-in PHP type.
243
260
*/
244
- private function getPhpType (string $ doctrineType ): ?string
261
+ private function getPhpType (string $ doctrineType ): ?TypeIdentifier
245
262
{
246
263
return match ($ doctrineType ) {
247
264
Types::SMALLINT ,
248
- Types::INTEGER => Type:: BUILTIN_TYPE_INT ,
249
- Types::FLOAT => Type:: BUILTIN_TYPE_FLOAT ,
265
+ Types::INTEGER => TypeIdentifier:: INT ,
266
+ Types::FLOAT => TypeIdentifier:: FLOAT ,
250
267
Types::BIGINT ,
251
268
Types::STRING ,
252
269
Types::TEXT ,
253
270
Types::GUID ,
254
- Types::DECIMAL => Type:: BUILTIN_TYPE_STRING ,
255
- Types::BOOLEAN => Type:: BUILTIN_TYPE_BOOL ,
271
+ Types::DECIMAL => TypeIdentifier:: STRING ,
272
+ Types::BOOLEAN => TypeIdentifier:: BOOL ,
256
273
Types::BLOB ,
257
- Types::BINARY => Type:: BUILTIN_TYPE_RESOURCE ,
274
+ Types::BINARY => TypeIdentifier:: RESOURCE ,
258
275
'object ' , // DBAL < 4
259
276
Types::DATE_MUTABLE ,
260
277
Types::DATETIME_MUTABLE ,
@@ -265,10 +282,10 @@ private function getPhpType(string $doctrineType): ?string
265
282
Types::DATETIME_IMMUTABLE ,
266
283
Types::DATETIMETZ_IMMUTABLE ,
267
284
Types::TIME_IMMUTABLE ,
268
- Types::DATEINTERVAL => Type:: BUILTIN_TYPE_OBJECT ,
285
+ Types::DATEINTERVAL => TypeIdentifier:: OBJECT ,
269
286
'array ' , // DBAL < 4
270
287
'json_array ' , // DBAL < 3
271
- Types::SIMPLE_ARRAY => Type:: BUILTIN_TYPE_ARRAY ,
288
+ Types::SIMPLE_ARRAY => TypeIdentifier:: ARRAY ,
272
289
default => null ,
273
290
};
274
291
}
0 commit comments