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 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) {
|
||||
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);
|
||||
});
|
||||
$dispatcher->connect(
|
||||
'TYPO3\Flow\Configuration\ConfigurationManager',
|
||||
'configurationManagerReady',
|
||||
function (ConfigurationManager $configurationManager) {
|
||||
$configurationManager->registerConfigurationType(
|
||||
'Validation',
|
||||
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ use TYPO3\Flow\Validation\ValidatorResolver;
|
|||
*
|
||||
* @Flow\Scope("prototype")
|
||||
*/
|
||||
class SettingsValidator extends AbstractValidator {
|
||||
class SettingsValidator extends AbstractValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ValidatorResolver
|
||||
|
@ -33,7 +34,9 @@ class SettingsValidator extends AbstractValidator {
|
|||
* @var \TYPO3\Flow\Configuration\ConfigurationManager
|
||||
*/
|
||||
protected $configurationManager;
|
||||
public function injectConfigurationManager(ConfigurationManager $configurationManager) {
|
||||
|
||||
public function injectConfigurationManager(ConfigurationManager $configurationManager)
|
||||
{
|
||||
$this->configurationManager = $configurationManager;
|
||||
$this->validations = $this->configurationManager->getConfiguration('Validation');
|
||||
}
|
||||
|
@ -45,7 +48,7 @@ class SettingsValidator extends AbstractValidator {
|
|||
protected $reflectionService;
|
||||
|
||||
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 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);
|
||||
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']);
|
||||
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);
|
||||
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'])));
|
||||
$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