TASK: Completely changing the layout of Validation.yaml

This commit is contained in:
Ferdinand Kuhl 2017-06-02 23:14:05 +02:00
parent 40fc82e515
commit 9a055a2f77
3 changed files with 42 additions and 22 deletions

View file

@ -75,7 +75,31 @@ class SettingsValidator extends AbstractValidator
); );
} }
$config = &$this->validations[$name]; $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;
}
}
}
foreach ($config as $validatorConfig) { foreach ($config as $validatorConfig) {
$validator = $this->validatorResolver->createValidator( $validator = $this->validatorResolver->createValidator(
$validatorConfig['validator'], $validatorConfig['validator'],

View file

@ -1,18 +1,14 @@
DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject: DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject:
- properties:
property: shouldBeTrue shouldBeTrue:
validator: BooleanValue BooleanValue:
options:
expectedValue: true expectedValue: true
- shouldBeFalse:
property: shouldBeFalse BooleanValue:
validator: BooleanValue
options:
expectedValue: false expectedValue: false
Grumble: ~
TrueValidator: TrueValidator:
- self:
validator: BooleanValue BooleanValue:
options:
expectedValue: true expectedValue: true

View file

@ -1,11 +1,11 @@
type: dictionary type: dictionary
additionalProperties: additionalProperties:
type: array
items:
type: dictionary type: dictionary
additionalProperties: false additionalProperties: false
# This validation sadly only hits the first level of validation, and options are not coverable with current validator
properties: properties:
validator: {type: string, required: true} type: dictionary
options: {type: dictionary, required: true} additionalProperties: false
property: {type: string, required: false} properties:
type: dictionary
self:
type: dictionary