mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized ParameterManagement
This commit is contained in:
@@ -9,6 +9,7 @@ use Infinito\Exception\NotDefinedException;
|
||||
|
||||
/**
|
||||
* @todo Rename class!
|
||||
* deprecated use ValidGetParameterService instead
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
@@ -17,7 +18,7 @@ class OptionalGetParameterService implements OptionalGetParameterServiceInterfac
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $currentRequest;
|
||||
protected $currentRequest;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
|
@@ -7,11 +7,12 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class VersionParameter extends AbstractParameter
|
||||
class VersionParameter extends AbstractParameter
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
* @Assert\GreaterThan(0)
|
||||
* @Assert\Type("integer")
|
||||
*/
|
||||
protected $value;
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ final class ParameterFactory implements ParameterFactoryInterface
|
||||
public function getParameter(string $key): ParameterInterface
|
||||
{
|
||||
$parameter = $this->parameters->get($key);
|
||||
if($parameter){
|
||||
if ($parameter) {
|
||||
return $parameter;
|
||||
}
|
||||
throw new NoValidChoiceException("The parameter for key <<$key>> doesn't exist!");
|
||||
|
@@ -21,6 +21,11 @@ final class ValidGetParametersService extends OptionalGetParameterService implem
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* @param RequestStack $requestStack
|
||||
* @param ParameterFactoryInterface $parameterFactory
|
||||
* @param ValidatorInterface $validator
|
||||
*/
|
||||
public function __construct(RequestStack $requestStack, ParameterFactoryInterface $parameterFactory, ValidatorInterface $validator)
|
||||
{
|
||||
$this->parameterFactory = $parameterFactory;
|
||||
@@ -37,6 +42,7 @@ final class ValidGetParametersService extends OptionalGetParameterService implem
|
||||
{
|
||||
parent::validateParameter($key);
|
||||
$parameter = $this->parameterFactory->getParameter($key);
|
||||
$parameter->setValue($this->currentRequest->get($key));
|
||||
$errors = $this->validator->validate($parameter);
|
||||
if (count($errors) > 0) {
|
||||
throw new UnvalidParameterException("Parameter <<$key>> didn't pass the validation");
|
||||
|
Reference in New Issue
Block a user