TASK: Only PSR-2 adherence
This commit is contained in:
parent
c81011f3e6
commit
cb418f5602
2 changed files with 90 additions and 63 deletions
|
@ -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->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady',
|
|
||||||
function(ConfigurationManager $configurationManager) {
|
|
||||||
$configurationManager->registerConfigurationType('Validation', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, TRUE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$dispatcher = $bootstrap->getSignalSlotDispatcher();
|
||||||
|
$dispatcher->connect(
|
||||||
|
'TYPO3\Flow\Configuration\ConfigurationManager',
|
||||||
|
'configurationManagerReady',
|
||||||
|
function (ConfigurationManager $configurationManager) {
|
||||||
|
$configurationManager->registerConfigurationType(
|
||||||
|
'Validation',
|
||||||
|
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,63 +16,81 @@ use TYPO3\Flow\Validation\ValidatorResolver;
|
||||||
*
|
*
|
||||||
* @Flow\Scope("prototype")
|
* @Flow\Scope("prototype")
|
||||||
*/
|
*/
|
||||||
class SettingsValidator extends AbstractValidator {
|
class SettingsValidator extends AbstractValidator
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ValidatorResolver
|
* @var ValidatorResolver
|
||||||
* @Flow\Inject
|
* @Flow\Inject
|
||||||
*/
|
*/
|
||||||
protected $validatorResolver;
|
protected $validatorResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $validations;
|
protected $validations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \TYPO3\Flow\Configuration\ConfigurationManager
|
* @var \TYPO3\Flow\Configuration\ConfigurationManager
|
||||||
*/
|
*/
|
||||||
protected $configurationManager;
|
protected $configurationManager;
|
||||||
public function injectConfigurationManager(ConfigurationManager $configurationManager) {
|
|
||||||
$this->configurationManager = $configurationManager;
|
|
||||||
$this->validations = $this->configurationManager->getConfiguration('Validation');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function injectConfigurationManager(ConfigurationManager $configurationManager)
|
||||||
* @var ReflectionService
|
{
|
||||||
* @Flow\Inject
|
$this->configurationManager = $configurationManager;
|
||||||
*/
|
$this->validations = $this->configurationManager->getConfiguration('Validation');
|
||||||
protected $reflectionService;
|
}
|
||||||
|
|
||||||
protected $supportedOptions = array(
|
/**
|
||||||
'name' => array('', 'Set the name of the setting-array to use', 'string', FALSE)
|
* @var ReflectionService
|
||||||
);
|
* @Flow\Inject
|
||||||
|
*/
|
||||||
|
protected $reflectionService;
|
||||||
|
|
||||||
/**
|
protected $supportedOptions = array(
|
||||||
* Check if $value is valid. If it is not valid, needs to add an error
|
'name' => array('', 'Set the name of the setting-array to use', 'string', false)
|
||||||
* to Result.
|
);
|
||||||
*
|
|
||||||
* @param mixed $value
|
/**
|
||||||
*
|
* Check if $value is valid. If it is not valid, needs to add an error
|
||||||
* @throws InvalidValidationOptionsException
|
* to Result.
|
||||||
* @throws InvalidValidationConfigurationException
|
*
|
||||||
*/
|
* @param mixed $value
|
||||||
protected function isValid($value) {
|
*
|
||||||
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject($value);
|
* @throws InvalidValidationOptionsException
|
||||||
if (! isset($this->validations[$name])) {
|
* @throws InvalidValidationConfigurationException
|
||||||
throw new InvalidValidationOptionsException('The name ' . $name . ' has not been defined in Validation.yaml!', 1397821438);
|
*/
|
||||||
}
|
protected function isValid($value)
|
||||||
$config = &$this->validations[$name];
|
{
|
||||||
foreach($config as $validatorConfig) {
|
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject(
|
||||||
$validator = $this->validatorResolver->createValidator($validatorConfig['validator'], $validatorConfig['options']);
|
$value
|
||||||
if (!$validator) {
|
);
|
||||||
throw new InvalidValidationConfigurationException('Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your validation.yaml', 1402326139);
|
if (!isset($this->validations[$name])) {
|
||||||
}
|
throw new InvalidValidationOptionsException(
|
||||||
if (isset($validatorConfig['property'])) {
|
'The name ' . $name . ' has not been defined in Validation.yaml!',
|
||||||
$this->result->forProperty($validatorConfig['property'])->merge($validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])));
|
1397821438
|
||||||
} else {
|
);
|
||||||
$this->result->merge($validator->validate($value));
|
}
|
||||||
}
|
$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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue