1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 Configuration Object project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\ConfigurationObject\Validation; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Core\Core; |
17
|
|
|
use Romm\ConfigurationObject\Reflection\ReflectionService; |
18
|
|
|
use Romm\ConfigurationObject\Validation\Validator\Internal\ConfigurationObjectValidator; |
19
|
|
|
use Romm\ConfigurationObject\Validation\Validator\Internal\MixedTypeCollectionValidator; |
20
|
|
|
use TYPO3\CMS\Extbase\Reflection\ReflectionService as ExtbaseReflectionService; |
21
|
|
|
use TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator; |
22
|
|
|
use TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator; |
23
|
|
|
use TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Customized validator resolver, which it mostly used to support the mixed |
27
|
|
|
* types. |
28
|
|
|
* |
29
|
|
|
* When an instance of validator is created, we check if the type of this |
30
|
|
|
* validator is `CollectionValidator`: in this case we use a custom one instead: |
31
|
|
|
* `MixedTypeCollectionValidator` which will support the mixed types feature. |
32
|
|
|
*/ |
33
|
|
|
class ValidatorResolver extends \TYPO3\CMS\Extbase\Validation\ValidatorResolver |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $baseValidatorConjunctionsWithChecks = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function createValidator($validatorType, array $validatorOptions = []) |
45
|
|
|
{ |
46
|
|
|
return (CollectionValidator::class === $validatorType) |
47
|
|
|
? parent::createValidator(MixedTypeCollectionValidator::class) |
48
|
|
|
: parent::createValidator($validatorType, $validatorOptions); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
*/ |
54
|
|
|
protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups = []) |
55
|
|
|
{ |
56
|
|
|
parent::buildBaseValidatorConjunction($indexKey, $targetClassName, $validationGroups); |
57
|
|
|
|
58
|
|
|
/* |
59
|
|
|
* The code below is DIRTY: in order to use `SilentExceptionInterface` |
60
|
|
|
* feature we need an extended version of the `GenericObjectValidator`, |
61
|
|
|
* but this is hardcoded in: |
62
|
|
|
* \TYPO3\CMS\Extbase\Validation\ValidatorResolver::buildBaseValidatorConjunction() |
63
|
|
|
* |
64
|
|
|
* Here we replace every `GenericObjectValidator` by our own instance. |
65
|
|
|
* |
66
|
|
|
* Please, do not try this at home. |
67
|
|
|
*/ |
68
|
|
|
/** @var ConjunctionValidator $conjunctionValidator */ |
69
|
|
|
$conjunctionValidator = $this->baseValidatorConjunctions[$indexKey]; |
70
|
|
|
|
71
|
|
|
foreach ($conjunctionValidator->getValidators() as $validator) { |
72
|
|
|
if ($validator instanceof GenericObjectValidator) { |
73
|
|
|
/** @var ConfigurationObjectValidator $newValidator */ |
74
|
|
|
$newValidator = $this->objectManager->get(ConfigurationObjectValidator::class, []); |
|
|
|
|
75
|
|
|
|
76
|
|
|
foreach ($validator->getPropertyValidators() as $propertyName => $propertyValidators) { |
77
|
|
|
foreach ($propertyValidators as $propertyValidator) { |
78
|
|
|
$newValidator->addPropertyValidator($propertyName, $propertyValidator); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$conjunctionValidator->removeValidator($validator); |
83
|
|
|
unset($validator); |
84
|
|
|
$conjunctionValidator->addValidator($newValidator); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param ExtbaseReflectionService $reflectionService |
91
|
|
|
*/ |
92
|
|
|
public function injectReflectionService(ExtbaseReflectionService $reflectionService) |
93
|
|
|
{ |
94
|
|
|
$this->reflectionService = Core::get()->getObjectManager()->get(ReflectionService::class); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.