From a1b81890b961a3be9d75638deae54db10b382980 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Wed, 29 Apr 2015 17:50:13 +0200 Subject: [PATCH] Adding License and small readme --- .../Validator/SettingsValidator.php | 7 +-- License.txt | 19 ++++++++ README.md | 46 +++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 License.txt create mode 100644 README.md diff --git a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php index 5fe9d23..92fe889 100644 --- a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php +++ b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php @@ -6,6 +6,7 @@ use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Configuration\ConfigurationManager; use TYPO3\Flow\Reflection\ObjectAccess; use TYPO3\Flow\Reflection\ReflectionService; +use TYPO3\Flow\Validation\Exception\InvalidValidationConfigurationException; use TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException; use TYPO3\Flow\Validation\Validator\AbstractValidator; use TYPO3\Flow\Validation\ValidatorResolver; @@ -51,8 +52,8 @@ class SettingsValidator extends AbstractValidator { * * @param mixed $value * - * @return void - * @throws \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException if invalid validation options have been specified in the constructor + * @throws InvalidValidationOptionsException + * @throws InvalidValidationConfigurationException */ protected function isValid($value) { $name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($value); @@ -63,7 +64,7 @@ class SettingsValidator extends AbstractValidator { foreach($config as $validatorConfig) { $validator = $this->validatorResolver->createValidator($validatorConfig['validator'], $validatorConfig['options']); if (!$validator) { - throw new \Exception('Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your validation.yaml', 1402326139); + throw new InvalidValidationConfigurationException('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']))); diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..c10feb1 --- /dev/null +++ b/License.txt @@ -0,0 +1,19 @@ +Copyright (c) 2015 Ferdinand Kuhl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5fae0b --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +DigiComp.SettingValidator +------------------------- + + +This Package allows to configure Validators for your Action-Arguments or domain model properties to be set by a new +Yaml-File in your Configuration directory. + +Lets imagine you had this action-method: + + /** + * @param Order $order + * @Flow\Validate(type="DigiComp.SettingValidator:Settings") + */ + public function createOrder($order) {...} + +Then your Validation.yaml could look like this: + + SuperVendor\SuperPackage\Domain\Model\Order: + - + property: price + validator: NumberRange + options: + maximum: 20 + minimum: 10 + - + validator: SuperVendor.SuperPackage:SomeOtherValidator #validates the complete object + options: [] + - + property: customer + validator: DigiComp.SettingValidator:Settings + options: + name: OrderCustomer + + OrderCustomer: + - + property: firstName + validator: StringLength + options: + minimum: 3 + maximum: 20 + + +As you see: Nesting is possible ;) That way you can easily construct flexible structures. + +The SettingsValidator has an optional option: "name" - If you don't give one, it assumes your validation value is an +object and searches in Validation.yaml for the FQCN. \ No newline at end of file