Initial commit

This commit is contained in:
Ferdinand Kuhl 2014-04-18 14:20:28 +02:00
commit 74cb20b8fa
4 changed files with 115 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.svn

View file

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

View file

@ -0,0 +1,72 @@
<?php
namespace DigiComp\SettingValidator\Validation\Validator;
use Doctrine\ORM\Mapping as ORM;
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\InvalidValidationOptionsException;
use TYPO3\Flow\Validation\Validator\AbstractValidator;
use TYPO3\Flow\Validation\ValidatorResolver;
/**
* @Flow\Scope("prototype")
*/
class SettingsValidator extends AbstractValidator {
/**
* @var ValidatorResolver
* @Flow\Inject
*/
protected $validatorResolver;
/**
* @var array
*/
protected $validations;
/**
* @var \TYPO3\Flow\Configuration\ConfigurationManager
*/
protected $configurationManager;
public function injectConfigurationManager(ConfigurationManager $configurationManager) {
$this->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));
}
}
}
}

18
composer.json Normal file
View file

@ -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"
}
}
}