update project; fit neos/flow 4

This commit is contained in:
Robin Krahnen 2017-03-13 17:00:13 +01:00
parent 9531b7af46
commit baa35e0926
4 changed files with 55 additions and 48 deletions

View file

@ -1,27 +1,27 @@
<?php
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;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
/**
* @Flow\Scope("prototype")
*/
class Package extends BasePackage
{
/**
* @param Bootstrap $bootstrap
*/
public function boot(Bootstrap $bootstrap)
{
parent::boot($bootstrap);
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(
'TYPO3\Flow\Configuration\ConfigurationManager',
'configurationManagerReady',
function (ConfigurationManager $configurationManager) {
$dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady',
function ($configurationManager) {
/** @var ConfigurationManager $configurationManager */
$configurationManager->registerConfigurationType(
'Validation',
ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,

View file

@ -1,15 +1,15 @@
<?php
namespace DigiComp\SettingValidator\Validation\Validator;
use Doctrine\ORM\Mapping as ORM;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Reflection\ObjectAccess;
use TYPO3\Flow\Reflection\ReflectionService;
use TYPO3\Flow\Validation\Exception\InvalidValidationConfigurationException;
use TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException;
use TYPO3\Flow\Validation\Validator\AbstractValidator;
use TYPO3\Flow\Validation\ValidatorResolver;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Reflection\ReflectionService;
use Neos\Flow\Validation\Exception\InvalidValidationConfigurationException;
use Neos\Flow\Validation\Exception\InvalidValidationOptionsException;
use Neos\Flow\Validation\Validator\AbstractValidator;
use Neos\Flow\Validation\ValidatorResolver;
use Neos\Utility\ObjectAccess;
use Neos\Utility\TypeHandling;
/**
* Validator resolving other Validators defined in Validation.yaml
@ -18,7 +18,6 @@ use TYPO3\Flow\Validation\ValidatorResolver;
*/
class SettingsValidator extends AbstractValidator
{
/**
* @var ValidatorResolver
* @Flow\Inject
@ -26,30 +25,36 @@ class SettingsValidator extends AbstractValidator
protected $validatorResolver;
/**
* @var array
*/
protected $validations;
/**
* @var \TYPO3\Flow\Configuration\ConfigurationManager
* @var ConfigurationManager
*/
protected $configurationManager;
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation');
}
/**
* @var ReflectionService
* @Flow\Inject
*/
protected $reflectionService;
protected $supportedOptions = array(
'name' => array('', 'Set the name of the setting-array to use', 'string', false)
);
/**
* @var array
*/
protected $supportedOptions = [
'name' => ['', 'Set the name of the setting-array to use', 'string', false]
];
/**
* @var array
*/
protected $validations;
/**
* @param ConfigurationManager $configurationManager
*/
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->validations = $this->configurationManager->getConfiguration('Validation');
}
/**
* Check if $value is valid. If it is not valid, needs to add an error
@ -62,33 +67,34 @@ class SettingsValidator extends AbstractValidator
*/
protected function isValid($value)
{
$name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject(
$value
);
if (!isset($this->validations[$name])) {
$name = $this->options['name'] ? $this->options['name'] : TypeHandling::getTypeForValue($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']
);
if (!$validator) {
if (! $validator) {
throw new InvalidValidationConfigurationException(
'Validator could not be resolved: ' .
$validatorConfig['validator'] . '. Check your Validation.yaml',
'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 {
}
else {
$this->result->merge($validator->validate($value));
}
}

View file

@ -6,6 +6,6 @@ additionalProperties:
additionalProperties: false
# This validation sadly only hits the first level of validation, and options are not coverable with current validator
properties:
validator: {type: string, required: TRUE}
options: {type: dictionary, required: TRUE}
property: {type: string, required: FALSE}
validator: {type: string, required: true}
options: {type: dictionary, required: true}
property: {type: string, required: false}

View file

@ -1,7 +1,7 @@
{
"name": "digicomp/settingvalidator",
"type": "typo3-flow-package",
"description": "Just a TYPO3\\Flow Validator resolving other Validators with Configuration/Validation.yaml",
"type": "neos-package",
"description": "Just a Neos\\Flow Validator resolving other Validators with Configuration/Validation.yaml",
"authors": [
{
"name": "Ferdinand Kuhl",
@ -13,6 +13,7 @@
"license": "MIT",
"homepage": "https://github.com/fcool/DigiComp.SettingValidator",
"keywords": [
"Neos",
"Flow",
"validation"
],