TASK: Only PSR-2 adherence

This commit is contained in:
Ferdinand Kuhl 2016-08-01 01:00:29 +02:00
parent c81011f3e6
commit cb418f5602
2 changed files with 90 additions and 63 deletions

View file

@ -4,21 +4,30 @@ namespace DigiComp\SettingValidator;
use Doctrine\ORM\Mapping as ORM;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Core\Bootstrap;
use \TYPO3\Flow\Package\Package as BasePackage;
/**
* @Flow\Scope("prototype")
*/
class Package extends BasePackage {
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);
});
}
public function boot(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

@ -16,63 +16,81 @@ use TYPO3\Flow\Validation\ValidatorResolver;
*
* @Flow\Scope("prototype")
*/
class SettingsValidator extends AbstractValidator {
class SettingsValidator extends AbstractValidator
{
/**
* @var ValidatorResolver
* @Flow\Inject
*/
protected $validatorResolver;
/**
* @var ValidatorResolver
* @Flow\Inject
*/
protected $validatorResolver;
/**
* @var array
*/
protected $validations;
/**
* @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 \TYPO3\Flow\Configuration\ConfigurationManager
*/
protected $configurationManager;
/**
* @var ReflectionService
* @Flow\Inject
*/
protected $reflectionService;
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation');
}
protected $supportedOptions = array(
'name' => array('', 'Set the name of the setting-array to use', 'string', FALSE)
);
/**
* @var ReflectionService
* @Flow\Inject
*/
protected $reflectionService;
/**
* Check if $value is valid. If it is not valid, needs to add an error
* to Result.
*
* @param mixed $value
*
* @throws InvalidValidationOptionsException
* @throws InvalidValidationConfigurationException
*/
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 (!$validator) {
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'])));
} else {
$this->result->merge($validator->validate($value));
}
}
}
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
*
* @throws InvalidValidationOptionsException
* @throws InvalidValidationConfigurationException
*/
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 (!$validator) {
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']))
);
} else {
$this->result->merge($validator->validate($value));
}
}
}
}