['', 'Name of the setting array to use', 'string'], 'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework', 'array'], ]; /** * @inheritDoc * @throws InvalidValidationOptionsException * @throws InvalidValidationConfigurationException * @throws NoSuchValidatorException */ protected function isValid($value): void { $validations = $this->validations; $name = $this->options['name'] !== '' ? $this->options['name'] : TypeHandling::getTypeForValue($value); if (!isset($validations[$name])) { throw new InvalidValidationOptionsException( 'The name "' . $name . '" has not been defined in Validation.yaml!', 1397821438 ); } // @deprecated - converts old "self" to new structure if (isset($validations[$name]['self'])) { foreach ($validations[$name]['self'] as $validator => $options) { if (isset($validations[$name][$validator])) { throw new \RuntimeException('The validator "' . $validator . '" is already defined on parent level.', 1725000364); } $validations[$name][$validator] = $options; } unset($validations[$name]['self']); } // @deprecated - converts old "properties" to new structure if (isset($validations[$name]['properties'])) { if (isset($validations[$name]['DigiComp.SettingValidator:Properties'])) { throw new \RuntimeException('The validator "DigiComp.SettingValidator:Properties" is already defined on parent level.', 1725000396); } $validations[$name]['DigiComp.SettingValidator:Properties'] = [ 'validatorsForProperties' => $validations[$name]['properties'], ]; unset($validations[$name]['properties']); } $validatorConfigs = []; foreach ($validations[$name] as $validator => $options) { if ($options === null) { continue; } $validatorConfigs[] = [ 'validator' => $validator, 'options' => $options, ]; } 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()->merge($validator->validate($value)); } } /** * 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 ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings') { $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; } elseif (isset($validatorConfig['options']['validationGroups'])) { unset($validatorConfig['options']['validationGroups']); } } }