Initial commit
This commit is contained in:
commit
74cb20b8fa
4 changed files with 115 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.svn
|
24
Classes/DigiComp/SettingValidator/Package.php
Normal file
24
Classes/DigiComp/SettingValidator/Package.php
Normal 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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -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
18
composer.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue