update to newest standard
This commit is contained in:
parent
efdb8560a1
commit
e311c202bc
6 changed files with 32 additions and 52 deletions
|
@ -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');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|| \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'];
|
||||
|
|
|
@ -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'])) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"validation"
|
||||
],
|
||||
"require": {
|
||||
"neos/flow": "^6.2",
|
||||
"neos/flow": "^6.2.2",
|
||||
"php": "~7.4.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
Loading…
Reference in a new issue