-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types #35794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types #35794
Conversation
@@ -117,7 +117,9 @@ public function getTypes($class, $property, array $context = []) | |||
$typeOfField = $subMetadata->getTypeOfField($indexProperty); | |||
} | |||
|
|||
$collectionKeyType = $this->getPhpType($typeOfField); | |||
if (!$collectionKeyType = $this->getPhpType($typeOfField)) { | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Type()
requires a built in type a its first argument. If we cannot guess it (for custom types), then we cannot extract the property types.
@@ -234,7 +243,22 @@ private function getPhpType($doctrineType) | |||
return Type::BUILTIN_TYPE_RESOURCE; | |||
|
|||
case DBALType::OBJECT: | |||
case DBALType::DATE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPhpType
now handle all Doctrine core types.
return Type::BUILTIN_TYPE_OBJECT; | ||
|
||
case DBALType::TARRAY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realize "json" is the new name of "json_array", so "json_array" has the same problem IMO.
|
||
case DBALType::TARRAY: | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; | ||
if (!$builtinType = $this->getPhpType($typeOfField)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to refactor a bit here to avoid duplicate code and to avoid to process 2 times the $typeOfField.
Thank you @fancyweb. |
For #35604:
To guess the collection key type, the
getPhpType()
method is called. But it does not handle most objects and arrays core types. This is why an indexBy datetime does not work.For #35542:
When the php type cannot be guessed, null is returned. In this case, we cannot pass a valid builtin type to PropertyInfo Type, so we should return null.