Neos\Flow\Validation\ValidatorResolver::addCustomValidators PHP Method

addCustomValidators() protected method

A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and append 'Validator'". If found, it will be added to the $conjunctionValidator. In addition canValidate() will be called on all implementations of the ObjectValidatorInterface to find all validators that could validate the target. The one with the highest priority will be added as well. If multiple validators have the same priority, which one will be added is not deterministic.
protected addCustomValidators ( string $targetClassName, ConjunctionValidator &$conjunctionValidator ) : null | Neos\Flow\Validation\Validator\ObjectValidatorInterface
$targetClassName string
$conjunctionValidator Neos\Flow\Validation\Validator\ConjunctionValidator
return null | Neos\Flow\Validation\Validator\ObjectValidatorInterface
    protected function addCustomValidators($targetClassName, ConjunctionValidator &$conjunctionValidator)
    {
        // Custom validator for the class
        $addedValidatorClassName = null;
        $possibleValidatorClassName = str_replace('\\Model\\', '\\Validator\\', $targetClassName) . 'Validator';
        $customValidator = $this->createValidator($possibleValidatorClassName);
        if ($customValidator !== null) {
            $conjunctionValidator->addValidator($customValidator);
            $addedValidatorClassName = get_class($customValidator);
        }
        // find polytype validator for class
        $acceptablePolyTypeValidators = [];
        $polyTypeObjectValidatorImplementationClassNames = static::getPolyTypeObjectValidatorImplementationClassNames($this->objectManager);
        foreach ($polyTypeObjectValidatorImplementationClassNames as $validatorImplementationClassName) {
            $acceptablePolyTypeValidator = $this->createValidator($validatorImplementationClassName);
            // skip custom validator already added above
            if ($addedValidatorClassName === get_class($acceptablePolyTypeValidator)) {
                continue;
            }
            if ($acceptablePolyTypeValidator->canValidate($targetClassName)) {
                $acceptablePolyTypeValidators[$acceptablePolyTypeValidator->getPriority()] = $acceptablePolyTypeValidator;
            }
        }
        if (count($acceptablePolyTypeValidators) > 0) {
            ksort($acceptablePolyTypeValidators);
            $conjunctionValidator->addValidator(array_pop($acceptablePolyTypeValidators));
        }
    }