From 74cb20b8fab48104889697ed811e7b0f9d4a1e29 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 18 Apr 2014 14:20:28 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + Classes/DigiComp/SettingValidator/Package.php | 24 +++++++ .../Validator/SettingsValidator.php | 72 +++++++++++++++++++ composer.json | 18 +++++ 4 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 Classes/DigiComp/SettingValidator/Package.php create mode 100644 Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90ec22b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.svn diff --git a/Classes/DigiComp/SettingValidator/Package.php b/Classes/DigiComp/SettingValidator/Package.php new file mode 100644 index 0000000..b912746 --- /dev/null +++ b/Classes/DigiComp/SettingValidator/Package.php @@ -0,0 +1,24 @@ +getSignalSlotDispatcher(); + $dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady', + function(ConfigurationManager $configurationManager) { + $configurationManager->registerConfigurationType('Validation', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, TRUE); + }); + } + +} diff --git a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php new file mode 100644 index 0000000..dd23fb5 --- /dev/null +++ b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php @@ -0,0 +1,72 @@ +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) + ); + + /** + * Check if $value is valid. If it is not valid, needs to add an error + * to Result. + * + * @param mixed $value + * + * @return void + * @throws \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException if invalid validation options have been specified in the constructor + */ + protected function isValid($value) { + $name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($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 (isset($validatorConfig['property'])) { + $this->result->forProperty($validatorConfig['property'])->merge($validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property']))); + } else { + $this->result->merge($validator->validate($value)); + } + } + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..610e96e --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name":"digicomp/settingvalidator", + "type":"typo3-flow-package", + "description":"", + "require":{ + "typo3/flow":"~2.0" + }, + "autoload":{ + "psr-0":{ + "DigiComp\\SettingValidator":"Classes" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} \ No newline at end of file