|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pgs\HashIdBundle\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Pgs\HashIdBundle\ParametersProcessor\Factory\DecodeParametersProcessorFactory; |
|
6
|
|
|
use Pgs\HashIdBundle\ParametersProcessor\ParametersProcessorInterface; |
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener; |
|
8
|
|
|
use Symfony\Component\HttpKernel\Event\KernelEvent; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractDecodeControllerParameters |
|
11
|
|
|
{ |
|
12
|
|
|
protected $parametersProcessorFactory; |
|
13
|
|
|
protected $paramConverterListener; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(DecodeParametersProcessorFactory $parametersProcessorFactory) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->parametersProcessorFactory = $parametersProcessorFactory; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getParamConverterListener(): ?ParamConverterListener |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->paramConverterListener; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function getParametersProcessorFactory(): DecodeParametersProcessorFactory |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->parametersProcessorFactory; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function setParamConverterListener(ParamConverterListener $paramConverterListener): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->paramConverterListener = $paramConverterListener; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function processRequestParametersWithParamConverter(KernelEvent $event): void |
|
36
|
|
|
{ |
|
37
|
|
|
if (null !== $this->getParamConverterListener()) { |
|
38
|
|
|
$this->getParamConverterListener()->onKernelController($event); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function processRequestParameters( |
|
43
|
|
|
KernelEvent $event, |
|
44
|
|
|
ParametersProcessorInterface $parametersProcessor |
|
45
|
|
|
): void { |
|
46
|
|
|
if ($parametersProcessor->needToProcess()) { |
|
47
|
|
|
$requestParams = $event->getRequest()->attributes->all(); |
|
48
|
|
|
$processedParams = $parametersProcessor->process($requestParams); |
|
49
|
|
|
$event->getRequest()->attributes->replace($processedParams); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|