@@ -122,6 +122,14 @@ abstract protected function normalizePropertyName(string $property): string;
122
122
*/
123
123
protected function getIdFromValue (string $ value ): mixed
124
124
{
125
+ if (is_numeric ($ value )) {
126
+ return $ value ;
127
+ }
128
+
129
+ if ($ this ->isValidUuid ($ value )) {
130
+ return $ value ;
131
+ }
132
+
125
133
try {
126
134
$ iriConverter = $ this ->getIriConverter ();
127
135
$ item = $ iriConverter ->getResourceFromIri ($ value , ['fetch_data ' => false ]);
@@ -163,16 +171,41 @@ protected function normalizeValues(array $values, string $property): ?array
163
171
}
164
172
165
173
/**
166
- * When the field should be an integer, check that the given value is a valid one .
174
+ * Check if the values are valid for the given Doctrine type .
167
175
*/
168
176
protected function hasValidValues (array $ values , ?string $ type = null ): bool
169
177
{
170
178
foreach ($ values as $ value ) {
171
- if (null !== $ value && \in_array ($ type , (array ) self ::DOCTRINE_INTEGER_TYPE , true ) && false === filter_var ($ value , \FILTER_VALIDATE_INT )) {
179
+ if (null === $ value ) {
180
+ continue ;
181
+ }
182
+
183
+ if (\in_array ($ type , (array ) self ::DOCTRINE_INTEGER_TYPE , true ) && false === filter_var ($ value , \FILTER_VALIDATE_INT )) {
184
+ return false ;
185
+ }
186
+
187
+ if ($ type === 'uuid ' && false === $ this ->isValidUuid ($ value )) {
172
188
return false ;
173
189
}
174
190
}
175
191
176
192
return true ;
177
193
}
194
+
195
+ protected function isValidUuid (mixed $ value ): bool
196
+ {
197
+ if (!\is_string ($ value )) {
198
+ return false ;
199
+ }
200
+
201
+ if (class_exists ('\Symfony\Component\Uid\Uuid ' )) {
202
+ return \Symfony \Component \Uid \Uuid::isValid ($ value );
203
+ }
204
+
205
+ if (class_exists ('\Ramsey\Uuid\Uuid ' )) {
206
+ return \Ramsey \Uuid \Uuid::isValid ($ value );
207
+ }
208
+
209
+ return \preg_match ('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i ' , $ value ) === 1 ;
210
+ }
178
211
}
0 commit comments