[TASK] Deprecate methods and constants in ValidatorResolver 88/56888/8
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Tue, 8 May 2018 13:06:46 +0000 (15:06 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 18 May 2018 14:04:16 +0000 (16:04 +0200)
Several methods and constants in the ValidatorResolver class
are now marked as deprecated because they are no longer needed
to resolve validators.

As these methods and constants are to be considered internal api
it is very unlikely that anyone is affected by this change.

Releases: master
Resolves: #85005
Change-Id: If5fdb34766c84de1b16854f14df23fc2ddaff750
Reviewed-on: https://review.typo3.org/56888
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php
typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php
typo3/sysext/extbase/Tests/UnitDeprecated/Validation/ValidatorResolverTest.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst
new file mode 100644 (file)
index 0000000..df93acd
--- /dev/null
@@ -0,0 +1,44 @@
+.. include:: ../../Includes.txt
+
+==========================================================================
+Deprecation: #85005 - Deprecate methods and constants in ValidatorResolver
+==========================================================================
+
+See :issue:`85005`
+
+Description
+===========
+
+The following methods within :php:`TYPO3\CMS\Extbase\Validation\ValidatorResolver` have been marked
+as deprecated:
+
+* buildSubObjectValidator
+* parseValidatorAnnotation
+* parseValidatorOptions
+* unquoteString
+
+The following constants within :php:`TYPO3\CMS\Extbase\Validation\ValidatorResolver` have been marked
+as deprecated:
+
+* PATTERN_MATCH_VALIDATORS
+* PATTERN_MATCH_VALIDATOROPTIONS
+
+Impact
+======
+
+Calling any of the deprecated methods above will trigger a PHP deprecation message.
+Using any of the deprecated constants above will not trigger a PHP deprecation message but will stop working in TYPO3 v10.0
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with a custom extension making use of these methods and constants. As these constants and methods
+are to be considered internal api it's very unlikely that anyone is affected by this change at all.
+
+Migration
+=========
+
+There is none.
+
+.. index:: PartiallyScanned, PHP-API, ext:extbase
index 7af8e5e..8e28b7a 100644 (file)
@@ -29,6 +29,7 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
     /**
      * Match validator names and options
      * @todo: adjust [a-z0-9_:.\\\\] once Tx_Extbase_Foo syntax is outdated.
+     * @deprecated and will be removed in TYPO3 v10.0.
      *
      * @var string
      */
@@ -48,6 +49,7 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
     /**
      * Match validator options (to parse actual options)
      * @var string
+     * @deprecated and will be removed in TYPO3 v10.0.
      */
     const PATTERN_MATCH_VALIDATOROPTIONS = '/
                        \s*
@@ -230,9 +232,15 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
      * @param array $objectPath The object path
      * @param \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator The validator which should be added to the property specified by objectPath
      * @return \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator
+     * @deprecated
      */
     protected function buildSubObjectValidator(array $objectPath, \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator)
     {
+        trigger_error(
+            'Method ' . __METHOD__ . ' is deprecated and will be removed in TYPO3 v10.0.',
+            E_USER_DEPRECATED
+        );
+
         $rootObjectValidator = $this->objectManager->get(\TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator::class, []);
         $parentObjectValidator = $rootObjectValidator;
 
@@ -370,6 +378,11 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function parseValidatorAnnotation($validateValue)
     {
+        trigger_error(
+            'Method ' . __METHOD__ . ' is deprecated and will be removed in TYPO3 v10.0.',
+            E_USER_DEPRECATED
+        );
+
         $matches = [];
         if ($validateValue[0] === '$') {
             $parts = explode(' ', $validateValue, 2);
@@ -395,9 +408,15 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
      *
      * @param string $rawValidatorOptions
      * @return array An array of optionName/optionValue pairs
+     * @deprecated
      */
     protected function parseValidatorOptions($rawValidatorOptions)
     {
+        trigger_error(
+            'Method ' . __METHOD__ . ' is deprecated and will be removed in TYPO3 v10.0.',
+            E_USER_DEPRECATED
+        );
+
         $validatorOptions = [];
         $parsedValidatorOptions = [];
         preg_match_all(self::PATTERN_MATCH_VALIDATOROPTIONS, $rawValidatorOptions, $validatorOptions, PREG_SET_ORDER);
@@ -415,9 +434,15 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface
      * This method is meant as a helper for regular expression results.
      *
      * @param string &$quotedValue Value to unquote
+     * @deprecated
      */
     protected function unquoteString(&$quotedValue)
     {
+        trigger_error(
+            'Method ' . __METHOD__ . ' is deprecated and will be removed in TYPO3 v10.0.',
+            E_USER_DEPRECATED
+        );
+
         switch ($quotedValue[0]) {
             case '"':
                 $quotedValue = str_replace('\\"', '"', trim($quotedValue, '"'));
index 1d3c26b..9bbcd41 100644 (file)
@@ -60,158 +60,4 @@ class ValidatorResolverTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCa
     {
         static::assertEquals('Raw', $this->validatorResolver->_call('getValidatorType', 'mixed'));
     }
-
-    /**
-     * dataProvider for parseValidatorAnnotationCanParseAnnotations
-     * @return array
-     */
-    public function validatorAnnotations(): array
-    {
-        return [
-            [
-                '$var Bar',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Bar', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            [
-                '$var Bar, Foo',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Bar', 'validatorOptions' => []],
-                        ['validatorName' => 'Foo', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            [
-                '$var Baz (Foo=Bar)',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => 'Bar']]
-                    ]
-                ]
-            ],
-            [
-                '$var Buzz (Foo="B=a, r", Baz=1)',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Buzz', 'validatorOptions' => ['Foo' => 'B=a, r', 'Baz' => '1']]
-                    ]
-                ]
-            ],
-            [
-                '$var Foo(Baz=1, Bar=Quux)',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Foo', 'validatorOptions' => ['Baz' => '1', 'Bar' => 'Quux']]
-                    ]
-                ]
-            ],
-            [
-                '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Pax', 'validatorOptions' => []],
-                        ['validatorName' => 'Foo', 'validatorOptions' => ['Baz' => '1', 'Bar' => 'Quux']]
-                    ]
-                ]
-            ],
-            [
-                '$var Reg (P="[at]*(h|g)"), Quux',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Reg', 'validatorOptions' => ['P' => '[at]*(h|g)']],
-                        ['validatorName' => 'Quux', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            [
-                '$var Baz (Foo="B\\"ar")',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => 'B"ar']]
-                    ]
-                ]
-            ],
-            [
-                '$var F3_TestPackage_Quux',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'F3_TestPackage_Quux', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            [
-                '$var Baz(Foo="5"), Bar(Quux="123")',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => '5']],
-                        ['validatorName' => 'Bar', 'validatorOptions' => ['Quux' => '123']]
-                    ]
-                ]
-            ],
-            [
-                '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
-                [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => '2']],
-                        ['validatorName' => 'Bar', 'validatorOptions' => ['Quux' => '123', 'Pax' => 'a weird "string" with *freaky* \\stuff']]
-                    ]
-                ]
-            ],
-            'namespaced validator class name' => [
-                'annotation' => '$var F3\TestPackage\Quux',
-                'expected' => [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'F3\TestPackage\Quux', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            'shorthand notation for system validator' => [
-                'annotation' => '$var TYPO3.CMS.Mypkg:MySecond',
-                'expected' => [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'TYPO3.CMS.Mypkg:MySecond', 'validatorOptions' => []]
-                    ]
-                ]
-            ],
-            'shorthand notation for custom validator with parameter' => [
-                'annotation' => '$var Acme.Mypkg:MyThird(Foo="2")',
-                'expected' => [
-                    'argumentName' => 'var',
-                    'validators' => [
-                        ['validatorName' => 'Acme.Mypkg:MyThird', 'validatorOptions' => ['Foo' => '2']]
-                    ]
-                ]
-            ],
-        ];
-    }
-
-    /**
-     * @test
-     * @dataProvider validatorAnnotations
-     *
-     * @param mixed $annotation
-     * @param mixed $expectedResult
-     */
-    public function parseValidatorAnnotationCanParseAnnotations($annotation, $expectedResult)
-    {
-        $result = $this->validatorResolver->_call('parseValidatorAnnotation', $annotation);
-        static::assertEquals($result, $expectedResult);
-    }
 }
index 42e8907..113dfd9 100644 (file)
@@ -22,6 +22,15 @@ use TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationExcepti
  */
 class ValidatorResolverTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
 {
+    /**
+     * @var \TYPO3\CMS\Extbase\Validation\ValidatorResolver | \PHPUnit_Framework_MockObject_MockObject | \TYPO3\TestingFramework\Core\AccessibleObjectInterface
+     */
+    protected $validatorResolver;
+
+    protected function setUp()
+    {
+        $this->validatorResolver = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Validation\ValidatorResolver::class, ['dummy']);
+    }
 
     /**
      * @test
@@ -134,4 +143,158 @@ class ValidatorResolverTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCa
         $validatorResolver->_set('reflectionService', $mockReflectionService);
         $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
     }
+
+    /**
+     * dataProvider for parseValidatorAnnotationCanParseAnnotations
+     * @return array
+     */
+    public function validatorAnnotations(): array
+    {
+        return [
+            [
+                '$var Bar',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Bar', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            [
+                '$var Bar, Foo',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Bar', 'validatorOptions' => []],
+                        ['validatorName' => 'Foo', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            [
+                '$var Baz (Foo=Bar)',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => 'Bar']]
+                    ]
+                ]
+            ],
+            [
+                '$var Buzz (Foo="B=a, r", Baz=1)',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Buzz', 'validatorOptions' => ['Foo' => 'B=a, r', 'Baz' => '1']]
+                    ]
+                ]
+            ],
+            [
+                '$var Foo(Baz=1, Bar=Quux)',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Foo', 'validatorOptions' => ['Baz' => '1', 'Bar' => 'Quux']]
+                    ]
+                ]
+            ],
+            [
+                '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Pax', 'validatorOptions' => []],
+                        ['validatorName' => 'Foo', 'validatorOptions' => ['Baz' => '1', 'Bar' => 'Quux']]
+                    ]
+                ]
+            ],
+            [
+                '$var Reg (P="[at]*(h|g)"), Quux',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Reg', 'validatorOptions' => ['P' => '[at]*(h|g)']],
+                        ['validatorName' => 'Quux', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            [
+                '$var Baz (Foo="B\\"ar")',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => 'B"ar']]
+                    ]
+                ]
+            ],
+            [
+                '$var F3_TestPackage_Quux',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'F3_TestPackage_Quux', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            [
+                '$var Baz(Foo="5"), Bar(Quux="123")',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => '5']],
+                        ['validatorName' => 'Bar', 'validatorOptions' => ['Quux' => '123']]
+                    ]
+                ]
+            ],
+            [
+                '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
+                [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Baz', 'validatorOptions' => ['Foo' => '2']],
+                        ['validatorName' => 'Bar', 'validatorOptions' => ['Quux' => '123', 'Pax' => 'a weird "string" with *freaky* \\stuff']]
+                    ]
+                ]
+            ],
+            'namespaced validator class name' => [
+                'annotation' => '$var F3\TestPackage\Quux',
+                'expected' => [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'F3\TestPackage\Quux', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            'shorthand notation for system validator' => [
+                'annotation' => '$var TYPO3.CMS.Mypkg:MySecond',
+                'expected' => [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'TYPO3.CMS.Mypkg:MySecond', 'validatorOptions' => []]
+                    ]
+                ]
+            ],
+            'shorthand notation for custom validator with parameter' => [
+                'annotation' => '$var Acme.Mypkg:MyThird(Foo="2")',
+                'expected' => [
+                    'argumentName' => 'var',
+                    'validators' => [
+                        ['validatorName' => 'Acme.Mypkg:MyThird', 'validatorOptions' => ['Foo' => '2']]
+                    ]
+                ]
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider validatorAnnotations
+     *
+     * @param mixed $annotation
+     * @param mixed $expectedResult
+     */
+    public function parseValidatorAnnotationCanParseAnnotations($annotation, $expectedResult)
+    {
+        $result = $this->validatorResolver->_call('parseValidatorAnnotation', $annotation);
+        static::assertEquals($result, $expectedResult);
+    }
 }
index ce3deac..af8dbf5 100644 (file)
@@ -2221,4 +2221,32 @@ return [
             'Breaking-84877-MethodsOfLocalizationRepositoryChanged.rst',
         ],
     ],
+    'TYPO3\CMS\Extbase\Validation\ValidatorResolver->buildSubObjectValidator' => [
+        'numberOfMandatoryArguments' => 2,
+        'maximumNumberOfArguments' => 2,
+        'restFiles' => [
+            'Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst',
+        ],
+    ],
+    'TYPO3\CMS\Extbase\Validation\ValidatorResolver->parseValidatorAnnotation' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst',
+        ],
+    ],
+    'TYPO3\CMS\Extbase\Validation\ValidatorResolver->parseValidatorOptions' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst',
+        ],
+    ],
+    'TYPO3\CMS\Extbase\Validation\ValidatorResolver->unquoteString' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85005-DeprecateMethodsAndConstantsInValidatorResolver.rst',
+        ],
+    ],
 ];