Skip to content
Snippets Groups Projects
Commit dbce47d7 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Benni Mack
Browse files

[TASK] Separately extract @validate annotations

Separately exctracting the @validate annotations
makes resolving these annotations more testable.

Also this allows to deprecate the usage of @validate
in favor of a doctrine annotation.

Releases: master
Resolves: #83143
Change-Id: I4dfd93b58e08cd5c458abebee36e82e9ce03ad47
Reviewed-on: https://review.typo3.org/54838


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent b1413c7d
Branches
Tags
No related merge requests found
...@@ -179,6 +179,11 @@ class ClassSchema ...@@ -179,6 +179,11 @@ class ClassSchema
$this->properties[$propertyName]['annotations']['type'] = null; $this->properties[$propertyName]['annotations']['type'] = null;
$this->properties[$propertyName]['annotations']['cascade'] = null; $this->properties[$propertyName]['annotations']['cascade'] = null;
$this->properties[$propertyName]['annotations']['dependency'] = null; $this->properties[$propertyName]['annotations']['dependency'] = null;
$this->properties[$propertyName]['annotations']['validators'] = [];
if ($docCommentParser->isTaggedWith('validate')) {
$this->properties[$propertyName]['annotations']['validators'] = $docCommentParser->getTagValues('validate');
}
if ($annotationReader->getPropertyAnnotation($reflectionProperty, Lazy::class) instanceof Lazy) { if ($annotationReader->getPropertyAnnotation($reflectionProperty, Lazy::class) instanceof Lazy) {
$this->properties[$propertyName]['annotations']['lazy'] = true; $this->properties[$propertyName]['annotations']['lazy'] = true;
...@@ -301,9 +306,13 @@ class ClassSchema ...@@ -301,9 +306,13 @@ class ClassSchema
$this->methods[$methodName]['abstract'] = $reflectionMethod->isAbstract(); $this->methods[$methodName]['abstract'] = $reflectionMethod->isAbstract();
$this->methods[$methodName]['params'] = []; $this->methods[$methodName]['params'] = [];
$this->methods[$methodName]['tags'] = []; $this->methods[$methodName]['tags'] = [];
$this->methods[$methodName]['annotations'] = [];
$docCommentParser = new DocCommentParser(true); $docCommentParser = new DocCommentParser(true);
$docCommentParser->parseDocComment($reflectionMethod->getDocComment()); $docCommentParser->parseDocComment($reflectionMethod->getDocComment());
$this->methods[$methodName]['annotations']['validators'] = [];
foreach ($docCommentParser->getTagsValues() as $tag => $values) { foreach ($docCommentParser->getTagsValues() as $tag => $values) {
if ($tag === 'ignorevalidation') { if ($tag === 'ignorevalidation') {
trigger_error( trigger_error(
...@@ -311,6 +320,9 @@ class ClassSchema ...@@ -311,6 +320,9 @@ class ClassSchema
E_USER_DEPRECATED E_USER_DEPRECATED
); );
} }
if ($tag === 'validate') {
$this->methods[$methodName]['annotations']['validators'] = $values;
}
$this->methods[$methodName]['tags'][$tag] = array_map(function ($value) { $this->methods[$methodName]['tags'][$tag] = array_map(function ($value) {
return ltrim($value, '$'); return ltrim($value, '$');
}, $values); }, $values);
......
...@@ -347,4 +347,37 @@ class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ...@@ -347,4 +347,37 @@ class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
static::assertArrayNotHasKey('author', $tags); static::assertArrayNotHasKey('author', $tags);
static::assertArrayNotHasKey('version', $tags); static::assertArrayNotHasKey('version', $tags);
} }
/**
* @test
*/
public function classSchemaDetectsValidateAnnotation()
{
$classSchema = new ClassSchema(Fixture\DummyClassWithValidateAnnotation::class);
static::assertSame(
[],
$classSchema->getProperty('propertyWithoutValidateAnnotations')['annotations']['validators']
);
static::assertSame(
[
'NotEmpty',
'Empty (Foo=Bar)'
],
$classSchema->getProperty('propertyWithValidateAnnotations')['annotations']['validators']
);
static::assertSame(
[],
$classSchema->getMethod('methodWithoutValidateAnnotations')['annotations']['validators']
);
static::assertSame(
[
'$fooParam FooValidator (FooValidatorOptionKey=FooValidatorOptionValue)',
'$fooParam BarValidator'
],
$classSchema->getMethod('methodWithValidateAnnotations')['annotations']['validators']
);
}
} }
<?php
namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/**
* Fixture class with @validate annotations
*/
class DummyClassWithValidateAnnotation extends AbstractEntity
{
protected $propertyWithoutValidateAnnotations;
/**
* @validate NotEmpty
* @validate Empty (Foo=Bar)
*/
protected $propertyWithValidateAnnotations;
public function methodWithoutValidateAnnotations()
{
}
/**
* @param $fooParam
* @validate $fooParam FooValidator (FooValidatorOptionKey=FooValidatorOptionValue)
* @validate $fooParam BarValidator
*/
public function methodWithValidateAnnotations($fooParam)
{
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment