Skip to content

Commit 6b049a0

Browse files
committed
BUGFIX: Respect type declaration when building class-schema
Without this change, any class property is ignored, if it has no `@var` tag. As soon as a property lacks that tag, the early return in method `evaluateClassPropertyAnnotationsForSchema` kicks in. When using type declarations, this is nonsense, though. This change thus makes sure the type is fetched from the native type declaration if no `@var` tag is found. If a `@var` tag exists, it takes precedence. This allows to do things like this to declare typed collections: ```php /** * @var Collection<AnnotatedIdentitiesEntity> */ #[ORM\ManyToMany(indexBy: 'author')] protected Collection $annotatedIdentitiesEntities; ```
1 parent 017f30f commit 6b049a0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Neos.Flow/Classes/Reflection/ReflectionService.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,16 +1568,19 @@ protected function evaluateClassPropertyAnnotationsForSchema(ClassSchema $classS
15681568
return false;
15691569
}
15701570

1571-
if (!$this->isPropertyTaggedWith($className, $propertyName, 'var')) {
1572-
return false;
1573-
}
1574-
15751571
$varTagValues = $this->getPropertyTagValues($className, $propertyName, 'var');
15761572
if (count($varTagValues) > 1) {
15771573
throw new InvalidPropertyTypeException('More than one @var annotation given for "' . $className . '::$' . $propertyName . '"', 1367334366);
15781574
}
1575+
if (count($varTagValues) === 0) {
1576+
$declaredType = $this->getPropertyType($className, $propertyName);
1577+
} else {
1578+
$declaredType = strtok(trim(current($varTagValues), " \n\t"), " \n\t");
1579+
}
15791580

1580-
$declaredType = strtok(trim(current($varTagValues), " \n\t"), " \n\t");
1581+
if (!$declaredType) {
1582+
return false;
1583+
}
15811584

15821585
if ($this->isPropertyAnnotatedWith($className, $propertyName, ORM\Id::class)) {
15831586
$skipArtificialIdentity = true;

0 commit comments

Comments
 (0)