[!!!][TASK] Drop evaluation of @validate annotations 80/58880/5
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Sat, 10 Nov 2018 10:53:51 +0000 (11:53 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 21 Dec 2018 04:42:07 +0000 (05:42 +0100)
@validate annotations in (Extbase) models and
controllers are no longer evaluated and should be
replaced with its doctrine annotation replacement.

Releases: master
Resolves: #86898
Change-Id: I6799f0e8e7a6d9661c59f27c2aad589d6a807658
Reviewed-on: https://review.typo3.org/58880
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Documentation/Changelog/master/Breaking-87193-DeprecatedFunctionalityRemoved.rst
typo3/sysext/extbase/Classes/Reflection/ClassSchema.php
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParam.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParamTypeHint.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotations.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyModelWithValidateAnnotation.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/Validation/Validator/DummyValidator.php [deleted file]
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php

index 049a590..667a999 100644 (file)
@@ -213,34 +213,6 @@ class ClassSchema
                 }
             }
 
-            if ($docCommentParser->isTaggedWith('validate')) {
-                trigger_error(
-                    sprintf(
-                        'Property %s::%s is tagged with @validate which is deprecated and will be removed in TYPO3 v10.0.',
-                        $reflectionClass->getName(),
-                        $reflectionProperty->getName()
-                    ),
-                    E_USER_DEPRECATED
-                );
-
-                $validatorResolver = GeneralUtility::makeInstance(ValidatorResolver::class);
-
-                $validateValues = $docCommentParser->getTagValues('validate');
-                foreach ($validateValues as $validateValue) {
-                    $validatorConfiguration = $validatorResolver->parseValidatorAnnotation($validateValue);
-
-                    foreach ($validatorConfiguration['validators'] ?? [] as $validator) {
-                        $validatorObjectName = $validatorResolver->resolveValidatorObjectName($validator['validatorName']);
-
-                        $this->properties[$propertyName]['validators'][] = [
-                            'name' => $validator['validatorName'],
-                            'options' => $validator['validatorOptions'],
-                            'className' => $validatorObjectName,
-                        ];
-                    }
-                }
-            }
-
             if ($annotationReader->getPropertyAnnotation($reflectionProperty, Lazy::class) instanceof Lazy) {
                 $this->properties[$propertyName]['annotations']['lazy'] = true;
             }
@@ -341,42 +313,10 @@ class ClassSchema
             }
 
             foreach ($docCommentParser->getTagsValues() as $tag => $values) {
-                if ($tag === 'validate' && $this->isController && $this->methods[$methodName]['isAction']) {
-                    trigger_error(
-                        sprintf(
-                            'Method %s::%s is tagged with @validate which is deprecated and will be removed in TYPO3 v10.0.',
-                            $reflectionClass->getName(),
-                            $reflectionMethod->getName()
-                        ),
-                        E_USER_DEPRECATED
-                    );
-
-                    $validatorResolver = GeneralUtility::makeInstance(ValidatorResolver::class);
-
-                    foreach ($values as $validate) {
-                        $methodValidatorDefinition = $validatorResolver->parseValidatorAnnotation($validate);
-
-                        foreach ($methodValidatorDefinition['validators'] as $validator) {
-                            $validatorObjectName = $validatorResolver->resolveValidatorObjectName($validator['validatorName']);
-
-                            $argumentValidators[$methodValidatorDefinition['argumentName']][] = [
-                                'name' => $validator['validatorName'],
-                                'options' => $validator['validatorOptions'],
-                                'className' => $validatorObjectName,
-                            ];
-                        }
-                    }
-                }
-                $this->methods[$methodName]['tags'][$tag] = array_map(function ($value) use ($tag) {
-                    // not stripping the dollar sign for @validate annotations is just
-                    // a quick fix for a regression introduced in 9.0.0.
-                    // This exception to the rules will vanish once the resolving of
-                    // validators will take place inside this class and not in the
-                    // controller during runtime.
-                    return $tag === 'validate' ? $value : ltrim($value, '$');
+                $this->methods[$methodName]['tags'][$tag] = array_map(function ($value) {
+                    return ltrim($value, '$');
                 }, $values);
             }
-            unset($methodValidatorDefinition);
 
             foreach ($annotations as $annotation) {
                 if ($annotation instanceof IgnoreValidation) {
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php
deleted file mode 100644 (file)
index 09bdb7c..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection;
-
-/*
- * 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\Reflection\ClassSchema;
-use TYPO3\CMS\Extbase\Validation\Exception\InvalidTypeHintException;
-use TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException;
-use TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator;
-use TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator;
-use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
-
-/**
- * Test case
- */
-class ClassSchemaTest extends UnitTestCase
-{
-    /**
-     * @var bool Reset singletons created by subject
-     */
-    protected $resetSingletonInstances = true;
-
-    /**
-     * @test
-     */
-    public function classSchemaDetectsValidateAnnotationsModelProperties(): void
-    {
-        $classSchema = new ClassSchema(Fixture\DummyModelWithValidateAnnotation::class);
-
-        static::assertSame(
-            [
-                [
-                    'name' => 'StringLength',
-                    'options' => [
-                        'minimum' => '1',
-                        'maximum' => '10',
-                    ],
-                    'className' => StringLengthValidator::class
-                ],
-                [
-                    'name' => 'NotEmpty',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => 'TYPO3.CMS.Extbase:NotEmpty',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => 'TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator',
-                    'options' => [],
-                    'className' => Fixture\Validation\Validator\DummyValidator::class
-                ],
-                [
-                    'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => NotEmptyValidator::class,
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ]
-            ],
-            $classSchema->getProperty('propertyWithValidateAnnotations')['validators']
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function classSchemaDetectsValidateAnnotationsOfControllerActions(): void
-    {
-        $classSchema = new ClassSchema(Fixture\DummyControllerWithValidateAnnotations::class);
-
-        static::assertSame(
-            [
-                [
-                    'name' => 'StringLength',
-                    'options' => [
-                        'minimum' => '1',
-                        'maximum' => '10',
-                    ],
-                    'className' => StringLengthValidator::class
-                ],
-                [
-                    'name' => 'NotEmpty',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => 'TYPO3.CMS.Extbase:NotEmpty',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => 'TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator',
-                    'options' => [],
-                    'className' => Fixture\Validation\Validator\DummyValidator::class
-                ],
-                [
-                    'name' => '\TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator',
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ],
-                [
-                    'name' => NotEmptyValidator::class,
-                    'options' => [],
-                    'className' => NotEmptyValidator::class
-                ]
-            ],
-            $classSchema->getMethod('methodWithValidateAnnotationsAction')['params']['fooParam']['validators']
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function classSchemaGenerationThrowsExceptionWithValidateAnnotationsForParamWithoutTypeHint(): void
-    {
-        $this->expectException(InvalidTypeHintException::class);
-        $this->expectExceptionMessage('Missing type information for parameter "$fooParam" in TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint->methodWithValidateAnnotationsAction(): Either use an @param annotation or use a type hint.');
-        $this->expectExceptionCode(1515075192);
-
-        new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParamTypeHint::class);
-    }
-
-    /**
-     * @test
-     */
-    public function classSchemaGenerationThrowsExceptionWithValidateAnnotationsForMissingParam(): void
-    {
-        $this->expectException(InvalidValidationConfigurationException::class);
-        $this->expectExceptionMessage('Invalid validate annotation in TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture\DummyControllerWithValidateAnnotationWithoutParam->methodWithValidateAnnotationsAction(): The following validators have been defined for missing param "$fooParam": NotEmpty, StringLength');
-        $this->expectExceptionCode(1515073585);
-
-        new ClassSchema(Fixture\DummyControllerWithValidateAnnotationWithoutParam::class);
-    }
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParam.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParam.php
deleted file mode 100644 (file)
index 485f65c..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\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\Mvc\Controller\ActionController;
-
-/**
- * Fixture class with @validate annotations
- */
-class DummyControllerWithValidateAnnotationWithoutParam extends ActionController
-{
-    /**
-     * @validate $fooParam NotEmpty
-     * @validate $fooParam StringLength
-     */
-    public function methodWithValidateAnnotationsAction(): void
-    {
-    }
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParamTypeHint.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotationWithoutParamTypeHint.php
deleted file mode 100644 (file)
index 30d49df..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\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\Mvc\Controller\ActionController;
-
-/**
- * Fixture class with @validate annotations
- */
-class DummyControllerWithValidateAnnotationWithoutParamTypeHint extends ActionController
-{
-    /**
-     * @validate $fooParam NotEmpty
-     */
-    public function methodWithValidateAnnotationsAction($fooParam): void
-    {
-    }
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotations.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyControllerWithValidateAnnotations.php
deleted file mode 100644 (file)
index a53c417..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\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\Mvc\Controller\ActionController;
-
-/**
- * Fixture class with @validate annotations
- */
-class DummyControllerWithValidateAnnotations extends ActionController
-{
-    /**
-     * @param string $fooParam
-     * @validate $fooParam StringLength (minimum=1,maximum=10)
-     * @validate $fooParam NotEmpty
-     * @validate $fooParam TYPO3.CMS.Extbase:NotEmpty
-     * @validate $fooParam TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator
-     * @validate $fooParam \TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
-     * @validate $fooParam TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
-     */
-    public function methodWithValidateAnnotationsAction($fooParam)
-    {
-    }
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyModelWithValidateAnnotation.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyModelWithValidateAnnotation.php
deleted file mode 100644 (file)
index c0e50d3..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\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 model
- */
-class DummyModelWithValidateAnnotation extends AbstractEntity
-{
-    /**
-     * @validate StringLength (minimum=1,maximum=10)
-     * @validate NotEmpty
-     * @validate TYPO3.CMS.Extbase:NotEmpty
-     * @validate TYPO3.CMS.Extbase.Tests.UnitDeprecated.Reflection.Fixture:DummyValidator
-     * @validate \TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
-     * @validate TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
-     */
-    protected $propertyWithValidateAnnotations;
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/Validation/Validator/DummyValidator.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/Validation/Validator/DummyValidator.php
deleted file mode 100644 (file)
index 578d3ae..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-declare(strict_types = 1);
-namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture\Validation\Validator;
-
-/*
- * 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\Validation\Validator\ValidatorInterface;
-
-/**
- * Fixture validator
- */
-class DummyValidator implements ValidatorInterface
-{
-    /**
-     * @param mixed $value The value that should be validated
-     * @return \TYPO3\CMS\Extbase\Error\Result
-     */
-    public function validate($value)
-    {
-        return new \TYPO3\CMS\Extbase\Error\Result;
-    }
-
-    /**
-     * @return array
-     */
-    public function getOptions()
-    {
-        return [];
-    }
-}
index 91b4562..66ed8ef 100644 (file)
@@ -33,6 +33,7 @@ return [
         'restFiles' => [
             'Feature-83167-ReplaceValidateWithTYPO3CMSExtbaseAnnotationValidate.rst',
             'Deprecation-83167-ReplaceValidateWithTYPO3CMSExtbaseAnnotationValidate.rst',
+            'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
 ];