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\Configuration\ConfigurationManager;
|
||||||
use Neos\Flow\Core\Bootstrap;
|
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.
|
* 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
|
* @param Bootstrap $bootstrap
|
||||||
*/
|
*/
|
||||||
public function boot(Bootstrap $bootstrap)
|
public function boot(Bootstrap $bootstrap): void
|
||||||
{
|
{
|
||||||
parent::boot($bootstrap);
|
parent::boot($bootstrap);
|
||||||
|
|
||||||
|
@ -35,11 +33,7 @@ class Package extends BasePackage
|
||||||
ConfigurationManager::class,
|
ConfigurationManager::class,
|
||||||
'configurationManagerReady',
|
'configurationManagerReady',
|
||||||
function (ConfigurationManager $configurationManager) {
|
function (ConfigurationManager $configurationManager) {
|
||||||
$configurationManager->registerConfigurationType(
|
$configurationManager->registerConfigurationType('Validation');
|
||||||
self::CONFIGURATION_TYPE_VALIDATION,
|
|
||||||
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,7 @@ namespace DigiComp\SettingValidator\Validation\Validator;
|
||||||
* source code.
|
* source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use DigiComp\SettingValidator\Package;
|
|
||||||
use Neos\Flow\Annotations as Flow;
|
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\InvalidValidationConfigurationException;
|
||||||
use Neos\Flow\Validation\Exception\InvalidValidationOptionsException;
|
use Neos\Flow\Validation\Exception\InvalidValidationOptionsException;
|
||||||
use Neos\Flow\Validation\Exception\NoSuchValidatorException;
|
use Neos\Flow\Validation\Exception\NoSuchValidatorException;
|
||||||
|
@ -36,35 +33,30 @@ class SettingsValidator extends AbstractValidator
|
||||||
protected $validatorResolver;
|
protected $validatorResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Flow\Inject
|
* @Flow\InjectConfiguration(type="Validation")
|
||||||
* @var ConfigurationManager
|
|
||||||
*/
|
|
||||||
protected $configurationManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected array $supportedOptions = [
|
protected array $validations;
|
||||||
'name' => ['', 'Set the name of the setting-array to use.', 'string', false],
|
|
||||||
'validationGroups' => [
|
/**
|
||||||
['Default'],
|
* @inheritDoc
|
||||||
'Same as "Validation Groups" of Flow Framework. Defines the groups to execute.',
|
*/
|
||||||
'array',
|
protected $supportedOptions = [
|
||||||
false,
|
'name' => ['', 'Name of the setting array to use', 'string'],
|
||||||
],
|
'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework', 'array'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @throws InvalidConfigurationTypeException
|
|
||||||
* @throws InvalidValidationOptionsException
|
* @throws InvalidValidationOptionsException
|
||||||
* @throws InvalidValidationConfigurationException
|
* @throws InvalidValidationConfigurationException
|
||||||
* @throws NoSuchValidatorException
|
* @throws NoSuchValidatorException
|
||||||
*/
|
*/
|
||||||
protected function isValid($value)
|
protected function isValid($value): void
|
||||||
{
|
{
|
||||||
$validations = $this->configurationManager->getConfiguration(Package::CONFIGURATION_TYPE_VALIDATION);
|
$validations = $this->validations;
|
||||||
$name = $this->options['name'] ?: TypeHandling::getTypeForValue($value);
|
|
||||||
|
$name = $this->options['name'] !== '' ? $this->options['name'] : TypeHandling::getTypeForValue($value);
|
||||||
if (!isset($validations[$name])) {
|
if (!isset($validations[$name])) {
|
||||||
throw new InvalidValidationOptionsException(
|
throw new InvalidValidationOptionsException(
|
||||||
'The name "' . $name . '" has not been defined in Validation.yaml!',
|
'The name "' . $name . '" has not been defined in Validation.yaml!',
|
||||||
|
@ -152,12 +144,10 @@ class SettingsValidator extends AbstractValidator
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
!isset($validatorConfig['options']['validationGroups'])
|
!isset($validatorConfig['options']['validationGroups'])
|
||||||
|| !empty(
|
|| \array_intersect(
|
||||||
\array_intersect(
|
$validatorConfig['options']['validationGroups'],
|
||||||
$validatorConfig['options']['validationGroups'],
|
$this->options['validationGroups']
|
||||||
$this->options['validationGroups']
|
) !== []
|
||||||
)
|
|
||||||
)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +156,7 @@ class SettingsValidator extends AbstractValidator
|
||||||
*
|
*
|
||||||
* @param array $validatorConfig
|
* @param array $validatorConfig
|
||||||
*/
|
*/
|
||||||
protected function handleValidationGroups(array &$validatorConfig)
|
protected function handleValidationGroups(array &$validatorConfig): void
|
||||||
{
|
{
|
||||||
if ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings') {
|
if ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings') {
|
||||||
$validatorConfig['options']['validationGroups'] = $this->options['validationGroups'];
|
$validatorConfig['options']['validationGroups'] = $this->options['validationGroups'];
|
||||||
|
|
|
@ -12,19 +12,16 @@ class Version20170603120900 extends AbstractMigration
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getIdentifier()
|
public function getIdentifier(): string
|
||||||
{
|
{
|
||||||
return 'DigiComp.SettingValidator-20170603120900';
|
return 'DigiComp.SettingValidator-20170603120900';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function up(): void
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
{
|
||||||
$this->processConfiguration(
|
$this->processConfiguration(
|
||||||
Package::CONFIGURATION_TYPE_VALIDATION,
|
'Validation',
|
||||||
function (&$configuration) {
|
function (array &$configuration) {
|
||||||
foreach ($configuration as $validatorName => &$validators) {
|
foreach ($configuration as $validatorName => &$validators) {
|
||||||
// guard that protects configuration, which has already the new format:
|
// guard that protects configuration, which has already the new format:
|
||||||
if (isset($validators['properties']) || isset($validators['self'])) {
|
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
|
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.
|
Yaml-File in your Configuration directory.
|
||||||
|
|
|
@ -18,7 +18,7 @@ class SettingsValidatorTest extends FunctionalTestCase
|
||||||
* @test
|
* @test
|
||||||
* @throws InvalidValidationOptionsException
|
* @throws InvalidValidationOptionsException
|
||||||
*/
|
*/
|
||||||
public function ifNoNameIsGivenClassNameIsUsed()
|
public function ifNoNameIsGivenClassNameIsUsed(): void
|
||||||
{
|
{
|
||||||
$validator = $this->objectManager->get(SettingsValidator::class);
|
$validator = $this->objectManager->get(SettingsValidator::class);
|
||||||
$result = $validator->validate(new TestObject());
|
$result = $validator->validate(new TestObject());
|
||||||
|
@ -33,7 +33,7 @@ class SettingsValidatorTest extends FunctionalTestCase
|
||||||
* @throws InvalidValidationOptionsException
|
* @throws InvalidValidationOptionsException
|
||||||
* @throws NoSuchValidatorException
|
* @throws NoSuchValidatorException
|
||||||
*/
|
*/
|
||||||
public function conjunctionValidationWorksAsExpected()
|
public function conjunctionValidationWorksAsExpected(): void
|
||||||
{
|
{
|
||||||
$validatorResolver = $this->objectManager->get(ValidatorResolver::class);
|
$validatorResolver = $this->objectManager->get(ValidatorResolver::class);
|
||||||
$validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class);
|
$validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class);
|
||||||
|
@ -46,7 +46,7 @@ class SettingsValidatorTest extends FunctionalTestCase
|
||||||
* @test
|
* @test
|
||||||
* @throws InvalidValidationOptionsException
|
* @throws InvalidValidationOptionsException
|
||||||
*/
|
*/
|
||||||
public function defaultValidationGroupWorks()
|
public function defaultValidationGroupWorks(): void
|
||||||
{
|
{
|
||||||
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Default']]);
|
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Default']]);
|
||||||
$result = $validator->validate(new TestValidationGroupsDefaultObject());
|
$result = $validator->validate(new TestValidationGroupsDefaultObject());
|
||||||
|
@ -59,7 +59,7 @@ class SettingsValidatorTest extends FunctionalTestCase
|
||||||
* @test
|
* @test
|
||||||
* @throws InvalidValidationOptionsException
|
* @throws InvalidValidationOptionsException
|
||||||
*/
|
*/
|
||||||
public function customValidationGroupWorks()
|
public function customValidationGroupWorks(): void
|
||||||
{
|
{
|
||||||
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Custom']]);
|
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Custom']]);
|
||||||
$result = $validator->validate(new TestValidationGroupsCustomObject());
|
$result = $validator->validate(new TestValidationGroupsCustomObject());
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"validation"
|
"validation"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"neos/flow": "^6.2",
|
"neos/flow": "^6.2.2",
|
||||||
"php": "~7.4.0"
|
"php": "~7.4.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|
Loading…
Reference in a new issue