Breaking: #107229 - Removed support for annotations in Extbase
See forge#107229
Description
Extbase no longer supports PHP annotations for Models, DTOs, and controller
actions. Use PHP attributes (e.g.
#
) instead, which
provide the same functionality with better performance and native language
support.
Note
With this change, the third-party library doctrine/annotations is no longer required by Extbase. The library itself suggests switching to PHP attributes since version 1.14.0 and is marked as abandoned.
Important
Note that usage of PHPDoc annotations like
@var
,
@return
and others are unaffected by this change, as they do not require specific
Doctrine annotation parsing. Especially explicit parameter type annotations
like
@var Object
are still fully supported.
Extbase made heavy use of annotation parsing, which can be detected via code such as this, where the annotation namespace was imported:
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
/**
* @Extbase\Validate("NotEmpty")
*/
protected string $foo = '';
}
Since PHP 8.2 is used as minimum requirement in TYPO3, the well-established PHP attributes should be used instead. All Extbase-related annotations are already usable as PHP attributes since TYPO3 v12.
Impact
By dropping support for Extbase annotations, the more type-safe and native use of PHP attributes comes into play. This will enhance validation and ORM-related integrations a lot, since developers can rely on well-established architectures without the need of maintaining an additional third-party feature.
Affected installations
All Extbase models, DTOs and Extbase controllers which make use of Extbase
annotations are affected. This covers all shipped annotations like
Cascade
,
Lazy
and
Validate
, as well as custom developed
annotations.
Migration
Switch from Extbase annotations to native PHP attributes.
Before (with annotations):
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
/**
* @Extbase\Validate("NotEmpty")
*/
protected string $foo = '';
}
After (with PHP Attributes):
use TYPO3\CMS\Extbase\Attribute as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
#[Extbase\Validate(['validator' => 'NotEmpty'])]
protected string $foo = '';
}
Note
Namespaces of all attribute classes have been moved from
\TYPO3\
to
\TYPO3\
.
A class alias map is provided to allow further usage of the previous namespaces. Since the previous namespaces are considered deprecated, developers should migrate usages of the attribute classes to avoid misbehaviour in the future.