[[], 'List of validators for properties. ', 'array', true], 'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework', 'array'], ]; /** * @inheritDoc * @throws InvalidValidationConfigurationException * @throws NoSuchValidatorException */ protected function isValid($value): void { $validatorConfigs = []; foreach ($this->options['validatorsForProperties'] as $property => $validators) { foreach ($validators as $validator => $options) { if ($options === null) { continue; } $validatorConfigs[] = [ 'validator' => $validator, 'options' => $options, 'property' => $property, ]; } } foreach ($validatorConfigs as $validatorConfig) { if (!$this->doesValidationGroupsMatch($validatorConfig)) { continue; } $this->handleValidationGroups($validatorConfig); $validator = $this->validatorResolver->createValidator( $validatorConfig['validator'], $validatorConfig['options'] ); if ($validator === null) { throw new InvalidValidationConfigurationException( \sprintf( 'Validator "%s" could not be resolved. Check your Validation.yaml', $validatorConfig['validator'] ), 1402326139 ); } $this->getResult()->forProperty($validatorConfig['property'])->merge( $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) ); } } /** * Check whether at least one configured group does match, if any is configured. * * @param array $validatorConfig * @return bool */ protected function doesValidationGroupsMatch(array $validatorConfig): bool { return !isset($validatorConfig['options']['validationGroups']) || \array_intersect( $validatorConfig['options']['validationGroups'], $this->options['validationGroups'] ) !== []; } /** * Add validation groups for recursion if necessary. * * @param array $validatorConfig */ protected function handleValidationGroups(array &$validatorConfig): void { if (\in_array($validatorConfig['validator'], ['DigiComp.SettingValidator:Settings', 'DigiComp.SettingValidator:Conditional', 'DigiComp.SettingValidator:Properties', 'Neos.Flow:Collection'])) { $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; } elseif (isset($validatorConfig['options']['validationGroups'])) { unset($validatorConfig['options']['validationGroups']); } } }