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) {
$validator = $this->validatorResolver->createValidator(
$validatorConfig['validator'],

View file

@ -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:
self:
BooleanValue:
expectedValue: true

View file

@ -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