Adding License and small readme
This commit is contained in:
parent
6eda039013
commit
a1b81890b9
3 changed files with 69 additions and 3 deletions
|
@ -6,6 +6,7 @@ use TYPO3\Flow\Annotations as Flow;
|
||||||
use TYPO3\Flow\Configuration\ConfigurationManager;
|
use TYPO3\Flow\Configuration\ConfigurationManager;
|
||||||
use TYPO3\Flow\Reflection\ObjectAccess;
|
use TYPO3\Flow\Reflection\ObjectAccess;
|
||||||
use TYPO3\Flow\Reflection\ReflectionService;
|
use TYPO3\Flow\Reflection\ReflectionService;
|
||||||
|
use TYPO3\Flow\Validation\Exception\InvalidValidationConfigurationException;
|
||||||
use TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException;
|
use TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException;
|
||||||
use TYPO3\Flow\Validation\Validator\AbstractValidator;
|
use TYPO3\Flow\Validation\Validator\AbstractValidator;
|
||||||
use TYPO3\Flow\Validation\ValidatorResolver;
|
use TYPO3\Flow\Validation\ValidatorResolver;
|
||||||
|
@ -51,8 +52,8 @@ class SettingsValidator extends AbstractValidator {
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
* @return void
|
* @throws InvalidValidationOptionsException
|
||||||
* @throws \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException if invalid validation options have been specified in the constructor
|
* @throws InvalidValidationConfigurationException
|
||||||
*/
|
*/
|
||||||
protected function isValid($value) {
|
protected function isValid($value) {
|
||||||
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($value);
|
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($value);
|
||||||
|
@ -63,7 +64,7 @@ class SettingsValidator extends AbstractValidator {
|
||||||
foreach($config as $validatorConfig) {
|
foreach($config as $validatorConfig) {
|
||||||
$validator = $this->validatorResolver->createValidator($validatorConfig['validator'], $validatorConfig['options']);
|
$validator = $this->validatorResolver->createValidator($validatorConfig['validator'], $validatorConfig['options']);
|
||||||
if (!$validator) {
|
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'])) {
|
if (isset($validatorConfig['property'])) {
|
||||||
$this->result->forProperty($validatorConfig['property'])->merge($validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])));
|
$this->result->forProperty($validatorConfig['property'])->merge($validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])));
|
||||||
|
|
19
License.txt
Normal file
19
License.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2015 Ferdinand Kuhl <f.kuhl@digital-competence.de>
|
||||||
|
|
||||||
|
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.
|
46
README.md
Normal file
46
README.md
Normal file
|
@ -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.
|
Loading…
Reference in a new issue