Skip to content

Commit 8e967b7

Browse files
committed
fix: Fetch property type from reflection if no var annotation is present
1 parent 87ae772 commit 8e967b7

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

Classes/Configuration/ConfigurationProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ protected function applyAnnotationBasedConfiguration(string $type, array $settin
114114
foreach ($reflection->getPropertyNamesByAnnotation($className, JsonApi\ExposeProperty::class) as $propertyName) {
115115
$annotation = $reflection->getPropertyAnnotation($className, $propertyName, JsonApi\ExposeProperty::class);
116116
assert($annotation instanceof JsonApi\ExposeProperty);
117-
$targetType = $reflection->getPropertyTagValues($className, $propertyName, 'var')[0];
117+
$propertyTagValues = $reflection->getPropertyTagValues($className, $propertyName, 'var');
118+
if (array_key_exists(0, $propertyTagValues)) {
119+
$targetType = $propertyTagValues[0];
120+
} else {
121+
$targetType = $reflection->getPropertyType($className, $propertyName);
122+
}
118123
$settings = $this->applyAnnotationBasedConfigurationForProperty(
119124
$propertyName,
120125
$annotation->exposeAsAttribute,

Classes/Resource/Information/ExposableTypeMap.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ protected static function collectKnownTypes(ObjectManagerInterface $objectManage
154154
array_walk(
155155
$propertyNames,
156156
function (string $propertyName) use ($className, $reflectionService, &$classNameToPropertyNamesMap) {
157-
$classNameToPropertyNamesMap[$className][$propertyName] = $reflectionService
158-
->getPropertyTagValues($className, $propertyName, 'var')[0]
159-
?: '';
157+
$propertyTagValues = $reflectionService->getPropertyTagValues($className, $propertyName, 'var');
158+
if (array_key_exists(0, $propertyTagValues)) {
159+
$typeName = $propertyTagValues[0] ?: '';
160+
} else {
161+
$typeName = $reflectionService->getPropertyType($className, $propertyName);
162+
}
163+
$classNameToPropertyNamesMap[$className][$propertyName] = $typeName;
160164
}
161165
);
162166

0 commit comments

Comments
 (0)