13
13
14
14
namespace ApiPlatform \Core \Bridge \Doctrine \Common \Util ;
15
15
16
+ use ApiPlatform \Core \Exception \InvalidIdentifierException ;
16
17
use ApiPlatform \Core \Exception \PropertyNotFoundException ;
17
18
use Doctrine \Common \Persistence \ObjectManager ;
19
+ use Doctrine \DBAL \Types \ConversionException ;
18
20
use Doctrine \DBAL \Types \Type as DBALType ;
19
21
use Doctrine \ODM \MongoDB \DocumentManager ;
20
22
use Doctrine \ODM \MongoDB \Types \Type as MongoDbType ;
@@ -34,6 +36,7 @@ trait IdentifierManagerTrait
34
36
* @param int|string $id
35
37
*
36
38
* @throws PropertyNotFoundException
39
+ * @throws InvalidIdentifierException
37
40
*/
38
41
private function normalizeIdentifiers ($ id , ObjectManager $ manager , string $ resourceClass ): array
39
42
{
@@ -76,11 +79,15 @@ private function normalizeIdentifiers($id, ObjectManager $manager, string $resou
76
79
77
80
$ doctrineTypeName = $ doctrineClassMetadata ->getTypeOfField ($ propertyName );
78
81
79
- if ($ isOrm && null !== $ doctrineTypeName && DBALType::hasType ($ doctrineTypeName )) {
80
- $ identifier = DBALType::getType ($ doctrineTypeName )->convertToPHPValue ($ identifier , $ platform );
81
- }
82
- if ($ isOdm && null !== $ doctrineTypeName && MongoDbType::hasType ($ doctrineTypeName )) {
83
- $ identifier = MongoDbType::getType ($ doctrineTypeName )->convertToPHPValue ($ identifier );
82
+ try {
83
+ if ($ isOrm && null !== $ doctrineTypeName && DBALType::hasType ($ doctrineTypeName )) {
84
+ $ identifier = DBALType::getType ($ doctrineTypeName )->convertToPHPValue ($ identifier , $ platform );
85
+ }
86
+ if ($ isOdm && null !== $ doctrineTypeName && MongoDbType::hasType ($ doctrineTypeName )) {
87
+ $ identifier = MongoDbType::getType ($ doctrineTypeName )->convertToPHPValue ($ identifier );
88
+ }
89
+ } catch (ConversionException $ e ) {
90
+ throw new InvalidIdentifierException (sprintf ('Invalid value "%s" provided for an identifier. ' , $ propertyName ), $ e ->getCode (), $ e );
84
91
}
85
92
86
93
$ identifiers [$ propertyName ] = $ identifier ;
0 commit comments