Merge branch 'feature/newValidationYamlLayout' into feature/neos-flow4

This commit is contained in:
Ferdinand Kuhl 2017-06-29 21:33:19 +02:00
commit f0e31dcc11
6 changed files with 139 additions and 28 deletions

View file

@ -1,16 +1,27 @@
<?php <?php
namespace DigiComp\SettingValidator; namespace DigiComp\SettingValidator;
use Neos\Flow\Annotations as Flow; /*
* This file is part of the DigiComp.SettingValidator package.
*
* (c) digital competence
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Core\Bootstrap; use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage; use Neos\Flow\Package\Package as BasePackage;
/** /**
* @Flow\Scope("prototype") * Package base class of the DigiComp.SettingValidator package.
*/ */
class Package extends BasePackage class Package extends BasePackage
{ {
const CONFIGURATION_TYPE_VALIDATION = 'Validation';
/** /**
* @param Bootstrap $bootstrap * @param Bootstrap $bootstrap
*/ */
@ -23,7 +34,7 @@ class Package extends BasePackage
function ($configurationManager) { function ($configurationManager) {
/** @var ConfigurationManager $configurationManager */ /** @var ConfigurationManager $configurationManager */
$configurationManager->registerConfigurationType( $configurationManager->registerConfigurationType(
'Validation', static::CONFIGURATION_TYPE_VALIDATION,
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
true true
); );

View file

@ -1,6 +1,16 @@
<?php <?php
namespace DigiComp\SettingValidator\Validation\Validator; namespace DigiComp\SettingValidator\Validation\Validator;
/*
* This file is part of the DigiComp.SettingValidator package.
*
* (c) digital competence
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow; use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Reflection\ReflectionService; use Neos\Flow\Reflection\ReflectionService;
@ -76,7 +86,8 @@ class SettingsValidator extends AbstractValidator
); );
} }
$config = &$this->validations[$name]; $config = $this->getConfigForName($name);
foreach ($config as $validatorConfig) { foreach ($config as $validatorConfig) {
if (! $this->doesValidationGroupsMatch($validatorConfig)) { if (! $this->doesValidationGroupsMatch($validatorConfig)) {
continue; continue;
@ -91,7 +102,10 @@ class SettingsValidator extends AbstractValidator
if (! $validator) { if (! $validator) {
throw new InvalidValidationConfigurationException( 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 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. * Check whether at least one configured group does match, if any is configured.
* *

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:
- BooleanValue:
property: shouldBeFalse expectedValue: false
validator: BooleanValue Grumble: ~
options:
expectedValue: false
TrueValidator: TrueValidator:
- self:
validator: BooleanValue BooleanValue:
options: expectedValue: true
expectedValue: true

View file

@ -0,0 +1,55 @@
<?php
namespace Neos\Flow\Core\Migrations;
/*
* This file is part of the DigiComp.SettingValidator package.
*
* (c) digital competence
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use DigiComp\SettingValidator\Package;
/**
* Restructures Validation.yamls to new format
*/
class Version20170603120900 extends AbstractMigration
{
public function getIdentifier()
{
return 'DigiComp.SettingValidator-20170603120900';
}
/**
* @return void
*/
public function up()
{
$this->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
);
}
}

View file

@ -1,11 +1,11 @@
type: dictionary type: dictionary
additionalProperties: additionalProperties:
type: array type: dictionary
items: additionalProperties: false
properties:
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} self:
property: {type: string, required: false} type: dictionary

View file

@ -65,7 +65,8 @@
"TYPO3.FluidAdaptor-20161130112935", "TYPO3.FluidAdaptor-20161130112935",
"Neos.Media-20161219094126", "Neos.Media-20161219094126",
"Neos.Flow-20170125103800", "Neos.Flow-20170125103800",
"Neos.Flow-20170127183102" "Neos.Flow-20170127183102",
"DigiComp.SettingValidator-20170603120900"
] ]
} }
} }