Deprecation: #83167 - Replace @validate with @TYPO3\CMS\Extbase\Annotation\Validate

See forge#83167

Description

The @validate annotation has been marked as deprecated and should be replaced with the doctrine annotation @TYPO3\CMS\Extbase\Annotation\Validate.

Impact

Classes using @validate will trigger a PHP E_USER_DEPRECATED error.

Affected Installations

All extensions that use @validate

Migration

Use @TYPO3\CMS\Extbase\Annotation\Validate instead.

Examples:

The following examples show both the old and the new way of using validation annotations. Both versions can still be used in the same doc block, but you should start using the new way today.

use TYPO3\CMS\Extbase\Annotation as Extbase;
Copied!

Validators for class properties

This is how annotations look like, that register validators without options

/**
 * @validate NotEmpty
 * @Extbase\Validate("NotEmpty")
 * @var Foo
 */
public $property;
Copied!
/**
 * @validate NotEmpty
 * @Extbase\Validate(validator="NotEmpty")
 * @var Foo
 */
public $property;
Copied!

This is how annotations look like, that register validators with options

/**
 * @validate StringLength(minimum=3, maximum=50)
 * @Extbase\Validate("StringLength", options={"minimum": 3, "maximum": 50})
 * @var Foo
 */
public $property;
Copied!
/**
 * @validate StringLength(minimum=3), StringLength(maximum=50)
 * @Extbase\Validate("StringLength", options={"minimum": 3})
 * @Extbase\Validate("StringLength", options={"maximum": 50})
 * @var Foo
 */
public $property;
Copied!

Validators for method params

/**
 * @validate $bar NotEmpty
 * @Extbase\Validate("NotEmpty", param="bar")
 * @var string $foo
 * @var string $bar
 */
public function method(string $foo, string $bar)
{
}
Copied!

Full qualified validator class names and aliases

Of course it's still possible to reference validators by extension key, aliases and FQCN's.

/**
 * @Extbase\Validate("NotEmpty")
 * @Extbase\Validate("TYPO3.CMS.Extbase:NotEmpty")
 * @Extbase\Validate("TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator")
 * @Extbase\Validate("\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator")
 */
protected $property;
Copied!