#96688Use PHP 8 Attributes for Extbase Annotations
Description
Since PHP 8, native attributes are supported. In comparison to doc comments, attributes have auto-completion, are better readable and were “invented” for storing meta-information about properties. For more info on attributes see https://stitcher.io/blog/attributes-in-php-8 and https://www.php.net/manual/en/language.attributes.overview.php
Extbase annotations are already nearly 1:1 translatable to attributes.
The following annotations have been enriched for usage as attributes:
Extbase\ORM\TransientExtbase\ORM\Cascade
@Extbase\ORM\Lazy
@Extbase\IgnoreValidation
@Extbase\Validate
Examples:
Before:
/**
* @Extbase\ORM\Cascade("remove")
*/
After:
#[Extbase\ORM\Cascade(['value' => 'remove'])]
With promoted properties in constructor:
public function __construct(
#[Extbase\Validate(['validator' => 'StringLength', 'options' => ['minimum' => 1, 'maximum' => 10]])]
#[Extbase\Validate(['validator' => 'NotEmpty'])]
#[Extbase\Validate(['validator' => 'TYPO3.CMS.Extbase:NotEmpty'])]
#[Extbase\Validate(['validator' => 'TYPO3.CMS.Extbase.Tests.Unit.Reflection.Fixture:DummyValidator'])]
#[Extbase\Validate(['validator' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator'])]
#[Extbase\Validate(['validator' => NotEmptyValidator::class])]
public readonly string $dummyPromotedProperty
)
{
}