From e311c202bcb9b0980287a6acd36bdbc1f1ee5727 Mon Sep 17 00:00:00 2001 From: Robin Krahnen Date: Wed, 22 Jul 2020 17:22:46 +0200 Subject: [PATCH] update to newest standard --- Classes/Package.php | 14 ++---- .../Validator/SettingsValidator.php | 46 ++++++++----------- Migrations/Code/Version20170603120900.php | 11 ++--- README.md | 3 +- Tests/Functional/SettingsValidatorTest.php | 8 ++-- composer.json | 2 +- 6 files changed, 32 insertions(+), 52 deletions(-) diff --git a/Classes/Package.php b/Classes/Package.php index 87279d3..cd71a3c 100644 --- a/Classes/Package.php +++ b/Classes/Package.php @@ -14,19 +14,17 @@ namespace DigiComp\SettingValidator; use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Core\Bootstrap; -use Neos\Flow\Package\Package as BasePackage; +use Neos\Flow\Package\Package as NeosFlowPackagePackage; /** * Package base class of the DigiComp.SettingValidator package. */ -class Package extends BasePackage +class Package extends NeosFlowPackagePackage { - public const CONFIGURATION_TYPE_VALIDATION = 'Validation'; - /** * @param Bootstrap $bootstrap */ - public function boot(Bootstrap $bootstrap) + public function boot(Bootstrap $bootstrap): void { parent::boot($bootstrap); @@ -35,11 +33,7 @@ class Package extends BasePackage ConfigurationManager::class, 'configurationManagerReady', function (ConfigurationManager $configurationManager) { - $configurationManager->registerConfigurationType( - self::CONFIGURATION_TYPE_VALIDATION, - ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, - true - ); + $configurationManager->registerConfigurationType('Validation'); } ); } diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 6c0acc6..0cdd08c 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -12,10 +12,7 @@ namespace DigiComp\SettingValidator\Validation\Validator; * source code. */ -use DigiComp\SettingValidator\Package; use Neos\Flow\Annotations as Flow; -use Neos\Flow\Configuration\ConfigurationManager; -use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException; use Neos\Flow\Validation\Exception\InvalidValidationConfigurationException; use Neos\Flow\Validation\Exception\InvalidValidationOptionsException; use Neos\Flow\Validation\Exception\NoSuchValidatorException; @@ -36,35 +33,30 @@ class SettingsValidator extends AbstractValidator protected $validatorResolver; /** - * @Flow\Inject - * @var ConfigurationManager - */ - protected $configurationManager; - - /** + * @Flow\InjectConfiguration(type="Validation") * @var array */ - protected array $supportedOptions = [ - 'name' => ['', 'Set the name of the setting-array to use.', 'string', false], - 'validationGroups' => [ - ['Default'], - 'Same as "Validation Groups" of Flow Framework. Defines the groups to execute.', - 'array', - false, - ], + protected array $validations; + + /** + * @inheritDoc + */ + protected $supportedOptions = [ + 'name' => ['', 'Name of the setting array to use', 'string'], + 'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework', 'array'], ]; /** * @inheritDoc - * @throws InvalidConfigurationTypeException * @throws InvalidValidationOptionsException * @throws InvalidValidationConfigurationException * @throws NoSuchValidatorException */ - protected function isValid($value) + protected function isValid($value): void { - $validations = $this->configurationManager->getConfiguration(Package::CONFIGURATION_TYPE_VALIDATION); - $name = $this->options['name'] ?: TypeHandling::getTypeForValue($value); + $validations = $this->validations; + + $name = $this->options['name'] !== '' ? $this->options['name'] : TypeHandling::getTypeForValue($value); if (!isset($validations[$name])) { throw new InvalidValidationOptionsException( 'The name "' . $name . '" has not been defined in Validation.yaml!', @@ -152,12 +144,10 @@ class SettingsValidator extends AbstractValidator { return !isset($validatorConfig['options']['validationGroups']) - || !empty( - \array_intersect( - $validatorConfig['options']['validationGroups'], - $this->options['validationGroups'] - ) - ) + || \array_intersect( + $validatorConfig['options']['validationGroups'], + $this->options['validationGroups'] + ) !== [] ; } @@ -166,7 +156,7 @@ class SettingsValidator extends AbstractValidator * * @param array $validatorConfig */ - protected function handleValidationGroups(array &$validatorConfig) + protected function handleValidationGroups(array &$validatorConfig): void { if ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings') { $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; diff --git a/Migrations/Code/Version20170603120900.php b/Migrations/Code/Version20170603120900.php index cf0d5c1..855ee6b 100644 --- a/Migrations/Code/Version20170603120900.php +++ b/Migrations/Code/Version20170603120900.php @@ -12,19 +12,16 @@ class Version20170603120900 extends AbstractMigration /** * @return string */ - public function getIdentifier() + public function getIdentifier(): string { return 'DigiComp.SettingValidator-20170603120900'; } - /** - * @return void - */ - public function up() + public function up(): void { $this->processConfiguration( - Package::CONFIGURATION_TYPE_VALIDATION, - function (&$configuration) { + 'Validation', + function (array &$configuration) { foreach ($configuration as $validatorName => &$validators) { // guard that protects configuration, which has already the new format: if (isset($validators['properties']) || isset($validators['self'])) { diff --git a/README.md b/README.md index 49a880a..fc438b7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -DigiComp.SettingValidator -------------------------- +# DigiComp.SettingValidator This Package allows configuring Validators for your Action-Arguments or domain model properties to be set by a new Yaml-File in your Configuration directory. diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php index ce6231a..305b515 100644 --- a/Tests/Functional/SettingsValidatorTest.php +++ b/Tests/Functional/SettingsValidatorTest.php @@ -18,7 +18,7 @@ class SettingsValidatorTest extends FunctionalTestCase * @test * @throws InvalidValidationOptionsException */ - public function ifNoNameIsGivenClassNameIsUsed() + public function ifNoNameIsGivenClassNameIsUsed(): void { $validator = $this->objectManager->get(SettingsValidator::class); $result = $validator->validate(new TestObject()); @@ -33,7 +33,7 @@ class SettingsValidatorTest extends FunctionalTestCase * @throws InvalidValidationOptionsException * @throws NoSuchValidatorException */ - public function conjunctionValidationWorksAsExpected() + public function conjunctionValidationWorksAsExpected(): void { $validatorResolver = $this->objectManager->get(ValidatorResolver::class); $validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class); @@ -46,7 +46,7 @@ class SettingsValidatorTest extends FunctionalTestCase * @test * @throws InvalidValidationOptionsException */ - public function defaultValidationGroupWorks() + public function defaultValidationGroupWorks(): void { $validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Default']]); $result = $validator->validate(new TestValidationGroupsDefaultObject()); @@ -59,7 +59,7 @@ class SettingsValidatorTest extends FunctionalTestCase * @test * @throws InvalidValidationOptionsException */ - public function customValidationGroupWorks() + public function customValidationGroupWorks(): void { $validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Custom']]); $result = $validator->validate(new TestValidationGroupsCustomObject()); diff --git a/composer.json b/composer.json index 0c31e5c..22a6d9e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "validation" ], "require": { - "neos/flow": "^6.2", + "neos/flow": "^6.2.2", "php": "~7.4.0" }, "autoload": {