From baa35e09261674b47d1596b0eac63ad9d29840b7 Mon Sep 17 00:00:00 2001 From: Robin Krahnen Date: Mon, 13 Mar 2017 17:00:13 +0100 Subject: [PATCH] update project; fit neos/flow 4 --- Classes/DigiComp/SettingValidator/Package.php | 20 +++--- .../Validator/SettingsValidator.php | 72 ++++++++++--------- .../Private/Schema/Validation.schema.yaml | 6 +- composer.json | 5 +- 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/Classes/DigiComp/SettingValidator/Package.php b/Classes/DigiComp/SettingValidator/Package.php index b7e328c..c821e77 100644 --- a/Classes/DigiComp/SettingValidator/Package.php +++ b/Classes/DigiComp/SettingValidator/Package.php @@ -1,27 +1,27 @@ getSignalSlotDispatcher(); - $dispatcher->connect( - 'TYPO3\Flow\Configuration\ConfigurationManager', - 'configurationManagerReady', - function (ConfigurationManager $configurationManager) { + $dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', + function ($configurationManager) { + /** @var ConfigurationManager $configurationManager */ $configurationManager->registerConfigurationType( 'Validation', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, diff --git a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php index f29f969..7132f62 100644 --- a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php +++ b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php @@ -1,15 +1,15 @@ configurationManager = $configurationManager; - $this->validations = $this->configurationManager->getConfiguration('Validation'); - } - /** * @var ReflectionService * @Flow\Inject */ 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 @@ -62,33 +67,34 @@ class SettingsValidator extends AbstractValidator */ protected function isValid($value) { - $name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject( - $value - ); - if (!isset($this->validations[$name])) { + $name = $this->options['name'] ? $this->options['name'] : TypeHandling::getTypeForValue($value); + if (! isset($this->validations[$name])) { throw new InvalidValidationOptionsException( 'The name ' . $name . ' has not been defined in Validation.yaml!', 1397821438 ); } + $config = &$this->validations[$name]; foreach ($config as $validatorConfig) { $validator = $this->validatorResolver->createValidator( $validatorConfig['validator'], $validatorConfig['options'] ); - if (!$validator) { + + if (! $validator) { throw new InvalidValidationConfigurationException( - 'Validator could not be resolved: ' . - $validatorConfig['validator'] . '. Check your Validation.yaml', + 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml', 1402326139 ); } + if (isset($validatorConfig['property'])) { $this->result->forProperty($validatorConfig['property'])->merge( $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) ); - } else { + } + else { $this->result->merge($validator->validate($value)); } } diff --git a/Resources/Private/Schema/Validation.schema.yaml b/Resources/Private/Schema/Validation.schema.yaml index 088e51b..b917695 100644 --- a/Resources/Private/Schema/Validation.schema.yaml +++ b/Resources/Private/Schema/Validation.schema.yaml @@ -6,6 +6,6 @@ additionalProperties: 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} + validator: {type: string, required: true} + options: {type: dictionary, required: true} + property: {type: string, required: false} diff --git a/composer.json b/composer.json index d94ec34..5328e01 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "digicomp/settingvalidator", - "type": "typo3-flow-package", - "description": "Just a TYPO3\\Flow Validator resolving other Validators with Configuration/Validation.yaml", + "type": "neos-package", + "description": "Just a Neos\\Flow Validator resolving other Validators with Configuration/Validation.yaml", "authors": [ { "name": "Ferdinand Kuhl", @@ -13,6 +13,7 @@ "license": "MIT", "homepage": "https://github.com/fcool/DigiComp.SettingValidator", "keywords": [ + "Neos", "Flow", "validation" ],