-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -137,39 +139,46 @@ public function getTypes($class, $property, array $context = []) | |
|
||
if ($metadata->hasField($property)) { | ||
$typeOfField = $metadata->getTypeOfField($property); | ||
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property); | ||
|
||
switch ($typeOfField) { | ||
case DBALType::DATE: | ||
case DBALType::DATETIME: | ||
case DBALType::DATETIMETZ: | ||
case 'vardatetime': | ||
case DBALType::TIME: | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')]; | ||
|
||
case 'date_immutable': | ||
case 'datetime_immutable': | ||
case 'datetimetz_immutable': | ||
case 'time_immutable': | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')]; | ||
|
||
case 'dateinterval': | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')]; | ||
|
||
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 commentThe 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. |
||
return null; | ||
} | ||
|
||
case DBALType::SIMPLE_ARRAY: | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]; | ||
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property); | ||
|
||
case DBALType::JSON_ARRAY: | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; | ||
switch ($builtinType) { | ||
case Type::BUILTIN_TYPE_OBJECT: | ||
switch ($typeOfField) { | ||
case DBALType::DATE: | ||
case DBALType::DATETIME: | ||
case DBALType::DATETIMETZ: | ||
case 'vardatetime': | ||
case DBALType::TIME: | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')]; | ||
|
||
case 'date_immutable': | ||
case 'datetime_immutable': | ||
case 'datetimetz_immutable': | ||
case 'time_immutable': | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')]; | ||
|
||
case 'dateinterval': | ||
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')]; | ||
} | ||
|
||
default: | ||
$builtinType = $this->getPhpType($typeOfField); | ||
break; | ||
case Type::BUILTIN_TYPE_ARRAY: | ||
switch ($typeOfField) { | ||
case DBALType::TARRAY: | ||
case DBALType::JSON_ARRAY: | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; | ||
|
||
return $builtinType ? [new Type($builtinType, $nullable)] : null; | ||
case DBALType::SIMPLE_ARRAY: | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]; | ||
} | ||
} | ||
|
||
return [new Type($builtinType, $nullable)]; | ||
} | ||
|
||
return null; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
case DBALType::DATETIME: | ||
case DBALType::DATETIMETZ: | ||
case 'vardatetime': | ||
case DBALType::TIME: | ||
case 'date_immutable': | ||
case 'datetime_immutable': | ||
case 'datetimetz_immutable': | ||
case 'time_immutable': | ||
case 'dateinterval': | ||
return Type::BUILTIN_TYPE_OBJECT; | ||
|
||
case DBALType::TARRAY: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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::SIMPLE_ARRAY: | ||
case DBALType::JSON_ARRAY: | ||
return Type::BUILTIN_TYPE_ARRAY; | ||
} | ||
|
||
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.