update project; fit neos/flow 4

This commit is contained in:
Robin Krahnen 2017-03-13 17:00:13 +01:00
parent 9531b7af46
commit baa35e0926
4 changed files with 55 additions and 48 deletions

View file

@ -1,27 +1,27 @@
<?php <?php
namespace DigiComp\SettingValidator; namespace DigiComp\SettingValidator;
use Doctrine\ORM\Mapping as ORM; use Neos\Flow\Annotations as Flow;
use TYPO3\Flow\Annotations as Flow; use Neos\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Configuration\ConfigurationManager; use Neos\Flow\Core\Bootstrap;
use TYPO3\Flow\Core\Bootstrap; use Neos\Flow\Package\Package as BasePackage;
use \TYPO3\Flow\Package\Package as BasePackage;
/** /**
* @Flow\Scope("prototype") * @Flow\Scope("prototype")
*/ */
class Package extends BasePackage class Package extends BasePackage
{ {
/**
* @param Bootstrap $bootstrap
*/
public function boot(Bootstrap $bootstrap) public function boot(Bootstrap $bootstrap)
{ {
parent::boot($bootstrap); parent::boot($bootstrap);
$dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect( $dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady',
'TYPO3\Flow\Configuration\ConfigurationManager', function ($configurationManager) {
'configurationManagerReady', /** @var ConfigurationManager $configurationManager */
function (ConfigurationManager $configurationManager) {
$configurationManager->registerConfigurationType( $configurationManager->registerConfigurationType(
'Validation', 'Validation',
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,

View file

@ -1,15 +1,15 @@
<?php <?php
namespace DigiComp\SettingValidator\Validation\Validator; namespace DigiComp\SettingValidator\Validation\Validator;
use Doctrine\ORM\Mapping as ORM; use Neos\Flow\Annotations as Flow;
use TYPO3\Flow\Annotations as Flow; use Neos\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Configuration\ConfigurationManager; use Neos\Flow\Reflection\ReflectionService;
use TYPO3\Flow\Reflection\ObjectAccess; use Neos\Flow\Validation\Exception\InvalidValidationConfigurationException;
use TYPO3\Flow\Reflection\ReflectionService; use Neos\Flow\Validation\Exception\InvalidValidationOptionsException;
use TYPO3\Flow\Validation\Exception\InvalidValidationConfigurationException; use Neos\Flow\Validation\Validator\AbstractValidator;
use TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException; use Neos\Flow\Validation\ValidatorResolver;
use TYPO3\Flow\Validation\Validator\AbstractValidator; use Neos\Utility\ObjectAccess;
use TYPO3\Flow\Validation\ValidatorResolver; use Neos\Utility\TypeHandling;
/** /**
* Validator resolving other Validators defined in Validation.yaml * Validator resolving other Validators defined in Validation.yaml
@ -18,7 +18,6 @@ use TYPO3\Flow\Validation\ValidatorResolver;
*/ */
class SettingsValidator extends AbstractValidator class SettingsValidator extends AbstractValidator
{ {
/** /**
* @var ValidatorResolver * @var ValidatorResolver
* @Flow\Inject * @Flow\Inject
@ -26,30 +25,36 @@ class SettingsValidator extends AbstractValidator
protected $validatorResolver; protected $validatorResolver;
/** /**
* @var array * @var ConfigurationManager
*/
protected $validations;
/**
* @var \TYPO3\Flow\Configuration\ConfigurationManager
*/ */
protected $configurationManager; protected $configurationManager;
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation');
}
/** /**
* @var ReflectionService * @var ReflectionService
* @Flow\Inject * @Flow\Inject
*/ */
protected $reflectionService; protected $reflectionService;
protected $supportedOptions = array( /**
'name' => array('', 'Set the name of the setting-array to use', 'string', false) * @var array
); */
protected $supportedOptions = [
'name' => ['', 'Set the name of the setting-array to use', 'string', false]
];
/**
* @var array
*/
protected $validations;
/**
* @param ConfigurationManager $configurationManager
*/
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation');
}
/** /**
* Check if $value is valid. If it is not valid, needs to add an error * Check if $value is valid. If it is not valid, needs to add an error
@ -62,33 +67,34 @@ class SettingsValidator extends AbstractValidator
*/ */
protected function isValid($value) protected function isValid($value)
{ {
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject( $name = $this->options['name'] ? $this->options['name'] : TypeHandling::getTypeForValue($value);
$value
);
if (! isset($this->validations[$name])) { if (! isset($this->validations[$name])) {
throw new InvalidValidationOptionsException( throw new InvalidValidationOptionsException(
'The name ' . $name . ' has not been defined in Validation.yaml!', 'The name ' . $name . ' has not been defined in Validation.yaml!',
1397821438 1397821438
); );
} }
$config = &$this->validations[$name]; $config = &$this->validations[$name];
foreach ($config as $validatorConfig) { foreach ($config as $validatorConfig) {
$validator = $this->validatorResolver->createValidator( $validator = $this->validatorResolver->createValidator(
$validatorConfig['validator'], $validatorConfig['validator'],
$validatorConfig['options'] $validatorConfig['options']
); );
if (! $validator) { if (! $validator) {
throw new InvalidValidationConfigurationException( throw new InvalidValidationConfigurationException(
'Validator could not be resolved: ' . 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml',
$validatorConfig['validator'] . '. Check your Validation.yaml',
1402326139 1402326139
); );
} }
if (isset($validatorConfig['property'])) { if (isset($validatorConfig['property'])) {
$this->result->forProperty($validatorConfig['property'])->merge( $this->result->forProperty($validatorConfig['property'])->merge(
$validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property']))
); );
} else { }
else {
$this->result->merge($validator->validate($value)); $this->result->merge($validator->validate($value));
} }
} }

View file

@ -6,6 +6,6 @@ additionalProperties:
additionalProperties: false additionalProperties: false
# This validation sadly only hits the first level of validation, and options are not coverable with current validator # 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} validator: {type: string, required: true}
options: {type: dictionary, required: TRUE} options: {type: dictionary, required: true}
property: {type: string, required: FALSE} property: {type: string, required: false}

View file

@ -1,7 +1,7 @@
{ {
"name": "digicomp/settingvalidator", "name": "digicomp/settingvalidator",
"type": "typo3-flow-package", "type": "neos-package",
"description": "Just a TYPO3\\Flow Validator resolving other Validators with Configuration/Validation.yaml", "description": "Just a Neos\\Flow Validator resolving other Validators with Configuration/Validation.yaml",
"authors": [ "authors": [
{ {
"name": "Ferdinand Kuhl", "name": "Ferdinand Kuhl",
@ -13,6 +13,7 @@
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/fcool/DigiComp.SettingValidator", "homepage": "https://github.com/fcool/DigiComp.SettingValidator",
"keywords": [ "keywords": [
"Neos",
"Flow", "Flow",
"validation" "validation"
], ],