diff --git a/Classes/Package.php b/Classes/Package.php index c821e77..06276a7 100644 --- a/Classes/Package.php +++ b/Classes/Package.php @@ -1,16 +1,27 @@ registerConfigurationType( - 'Validation', + static::CONFIGURATION_TYPE_VALIDATION, ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, true ); diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 40825a9..9ba1929 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -1,6 +1,16 @@ validations[$name]; + $config = $this->getConfigForName($name); + foreach ($config as $validatorConfig) { if (! $this->doesValidationGroupsMatch($validatorConfig)) { continue; @@ -91,7 +102,10 @@ class SettingsValidator extends AbstractValidator if (! $validator) { throw new InvalidValidationConfigurationException( - 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml', + sprintf( + 'Validator could not be resolved: "%s" Check your Validation.yaml', + $validatorConfig['validator'] + ), 1402326139 ); } @@ -106,6 +120,40 @@ class SettingsValidator extends AbstractValidator } } + /** + * @param $name + * + * @return array + */ + protected function getConfigForName($name): array + { + $config = []; + if (isset($this->validations[$name]['self'])) { + foreach ($this->validations[$name]['self'] as $validator => &$validation) { + if (is_null($validation)) { + continue; + } + $newValidation['options'] = $validation; + $newValidation['validator'] = $validator; + $config[] = $newValidation; + } + } + if (isset($this->validations[$name]['properties'])) { + foreach ($this->validations[$name]['properties'] as $propertyName => &$validation) { + foreach ($validation as $validator => &$options) { + if (is_null($options)) { + continue; + } + $newValidation['property'] = $propertyName; + $newValidation['validator'] = $validator; + $newValidation['options'] = $options; + $config[] = $newValidation; + } + } + } + return $config; + } + /** * Check whether at least one configured group does match, if any is configured. * diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml index f9575d2..bc17503 100644 --- a/Configuration/Testing/Validation.yaml +++ b/Configuration/Testing/Validation.yaml @@ -1,18 +1,14 @@ DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject: - - - property: shouldBeTrue - validator: BooleanValue - options: - expectedValue: true - - - property: shouldBeFalse - validator: BooleanValue - options: - expectedValue: false - + properties: + shouldBeTrue: + BooleanValue: + expectedValue: true + shouldBeFalse: + BooleanValue: + expectedValue: false + Grumble: ~ TrueValidator: - - - validator: BooleanValue - options: - expectedValue: true \ No newline at end of file + self: + BooleanValue: + expectedValue: true diff --git a/Migrations/Code/Version20170603120900.php b/Migrations/Code/Version20170603120900.php new file mode 100644 index 0000000..333c1a5 --- /dev/null +++ b/Migrations/Code/Version20170603120900.php @@ -0,0 +1,55 @@ +processConfiguration(Package::CONFIGURATION_TYPE_VALIDATION, + function (&$configuration) { + foreach ($configuration as $validatorName => &$validators) { + $newConfiguration = ['properties' => [], 'self' => []]; + + foreach ($validators as $key => &$validator) { + if (!isset($validator['validator']) || !isset($validator['options'])) { + $this->showWarning('The Validation.yaml files contained no validator or options for ' . + 'validation: "' . $validatorName . '.' . $key . '". It was not be migrated.'); + continue; + } + if (isset($validator['property'])) { + $newConfiguration['properties'][$validator['property']][$validator['validator']] + = $validator['options']; + } else { + $newConfiguration['self'][$validator['validator']] = $validator['options']; + } + } + $validators = $newConfiguration; + } + }, + true + ); + } +} diff --git a/Resources/Private/Schema/Validation.schema.yaml b/Resources/Private/Schema/Validation.schema.yaml index b917695..3f96d9d 100644 --- a/Resources/Private/Schema/Validation.schema.yaml +++ b/Resources/Private/Schema/Validation.schema.yaml @@ -1,11 +1,11 @@ type: dictionary additionalProperties: - type: array - items: + type: dictionary + additionalProperties: false + properties: type: dictionary additionalProperties: false - # This validation sadly only hits the first level of validation, and options are not coverable with current validator properties: - validator: {type: string, required: true} - options: {type: dictionary, required: true} - property: {type: string, required: false} + type: dictionary + self: + type: dictionary diff --git a/composer.json b/composer.json index a3cd64d..65020c7 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,8 @@ "TYPO3.FluidAdaptor-20161130112935", "Neos.Media-20161219094126", "Neos.Flow-20170125103800", - "Neos.Flow-20170127183102" + "Neos.Flow-20170127183102", + "DigiComp.SettingValidator-20170603120900" ] } -} +} \ No newline at end of file