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 Doctrine\ORM\Mapping as ORM;
use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Configuration\ConfigurationManager; use TYPO3\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Core\Bootstrap;
use \TYPO3\Flow\Package\Package as BasePackage; use \TYPO3\Flow\Package\Package as BasePackage;
/** /**
* @Flow\Scope("prototype") * @Flow\Scope("prototype")
*/ */
class Package extends BasePackage { class Package extends BasePackage
{
public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { public function boot(Bootstrap $bootstrap)
{
parent::boot($bootstrap); parent::boot($bootstrap);
$dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady', $dispatcher->connect(
function(ConfigurationManager $configurationManager) { 'TYPO3\Flow\Configuration\ConfigurationManager',
$configurationManager->registerConfigurationType('Validation', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, TRUE); 'configurationManagerReady',
}); function (ConfigurationManager $configurationManager) {
$configurationManager->registerConfigurationType(
'Validation',
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
true
);
}
);
} }
} }

View file

@ -16,7 +16,8 @@ use TYPO3\Flow\Validation\ValidatorResolver;
* *
* @Flow\Scope("prototype") * @Flow\Scope("prototype")
*/ */
class SettingsValidator extends AbstractValidator { class SettingsValidator extends AbstractValidator
{
/** /**
* @var ValidatorResolver * @var ValidatorResolver
@ -33,7 +34,9 @@ class SettingsValidator extends AbstractValidator {
* @var \TYPO3\Flow\Configuration\ConfigurationManager * @var \TYPO3\Flow\Configuration\ConfigurationManager
*/ */
protected $configurationManager; protected $configurationManager;
public function injectConfigurationManager(ConfigurationManager $configurationManager) {
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager; $this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation'); $this->validations = $this->configurationManager->getConfiguration('Validation');
} }
@ -45,7 +48,7 @@ class SettingsValidator extends AbstractValidator {
protected $reflectionService; protected $reflectionService;
protected $supportedOptions = array( protected $supportedOptions = array(
'name' => array('', 'Set the name of the setting-array to use', 'string', FALSE) 'name' => array('', 'Set the name of the setting-array to use', 'string', false)
); );
/** /**
@ -57,19 +60,34 @@ class SettingsValidator extends AbstractValidator {
* @throws InvalidValidationOptionsException * @throws InvalidValidationOptionsException
* @throws InvalidValidationConfigurationException * @throws InvalidValidationConfigurationException
*/ */
protected function isValid($value) { protected function isValid($value)
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($value); {
if (! isset($this->validations[$name])) { $name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject(
throw new InvalidValidationOptionsException('The name ' . $name . ' has not been defined in Validation.yaml!', 1397821438); $value
);
if (!isset($this->validations[$name])) {
throw new InvalidValidationOptionsException(
'The name ' . $name . ' has not been defined in Validation.yaml!',
1397821438
);
} }
$config = &$this->validations[$name]; $config = &$this->validations[$name];
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 InvalidValidationConfigurationException('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']))
);
} else { } else {
$this->result->merge($validator->validate($value)); $this->result->merge($validator->validate($value));
} }