mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Optimized Parameter logic
This commit is contained in:
		| @@ -24,7 +24,7 @@ class OptionalGetParameterService implements OptionalGetParameterServiceInterfac | ||||
|      * | ||||
|      * @throws UnvalidParameterException If the parameter is not valid | ||||
|      */ | ||||
|     private function validateParameter(string $key): void | ||||
|     protected function validateParameter(string $key): void | ||||
|     { | ||||
|         if (in_array($key, self::OPTIONAL_PARAMETERS)) { | ||||
|             return; | ||||
|   | ||||
| @@ -5,6 +5,9 @@ namespace Infinito\Domain\ParameterManagement; | ||||
| use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface ParameterFactoryInterface | ||||
| { | ||||
|     /** | ||||
|   | ||||
| @@ -7,10 +7,4 @@ namespace Infinito\Domain\ParameterManagement; | ||||
|  */ | ||||
| interface ValidGetParameterServiceInterface extends OptionalGetParameterServiceInterface | ||||
| { | ||||
|     /** | ||||
|      * @param string $key | ||||
|      * | ||||
|      * @return bool checks if the parameter is valid | ||||
|      */ | ||||
|     public function isValid(string $key): bool; | ||||
| } | ||||
|   | ||||
| @@ -2,12 +2,44 @@ | ||||
|  | ||||
| namespace Infinito\Domain\ParameterManagement; | ||||
|  | ||||
| use Infinito\Exception\UnvalidParameterException; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Component\Validator\Validator\ValidatorInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| final class ValidGetParametersService extends OptionalGetParameterService implements ValidGetParameterServiceInterface | ||||
| { | ||||
|     public function isValid(string $key): bool | ||||
|     /** | ||||
|      * @var ParameterFactoryInterface | ||||
|      */ | ||||
|     private $parameterFactory; | ||||
|  | ||||
|     /** | ||||
|      * @var ValidatorInterface | ||||
|      */ | ||||
|     private $validator; | ||||
|  | ||||
|     public function __construct(RequestStack $requestStack, ParameterFactoryInterface $parameterFactory, ValidatorInterface $validator) | ||||
|     { | ||||
|         $this->parameterFactory = $parameterFactory; | ||||
|         $this->validator = $validator; | ||||
|         parent::__construct($requestStack); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \Infinito\Domain\ParameterManagement\OptionalGetParameterService::validateParameter() | ||||
|      */ | ||||
|     protected function validateParameter(string $key): void | ||||
|     { | ||||
|         parent::validateParameter($key); | ||||
|         $parameter = $this->parameterFactory->getParameter($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