|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Pgs\HashIdBundle\ParametersProcessor\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Pgs\HashIdBundle\Annotation\Hash; |
|
8
|
|
|
use Pgs\HashIdBundle\AnnotationProvider\AnnotationProvider; |
|
9
|
|
|
use Pgs\HashIdBundle\Exception\InvalidControllerException; |
|
10
|
|
|
use Pgs\HashIdBundle\Exception\MissingClassOrMethodException; |
|
11
|
|
|
use Pgs\HashIdBundle\ParametersProcessor\ParametersProcessorInterface; |
|
12
|
|
|
|
|
13
|
|
|
class DecodeParametersProcessorFactory extends AbstractParametersProcessorFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ParametersProcessorInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $decodeParametersProcessor; |
|
19
|
|
|
|
|
20
|
2 |
|
public function __construct( |
|
21
|
|
|
AnnotationProvider $annotationProvider, |
|
22
|
|
|
ParametersProcessorInterface $noOpParametersProcessor, |
|
23
|
|
|
ParametersProcessorInterface $decodeParametersProcessor |
|
24
|
|
|
) { |
|
25
|
2 |
|
parent::__construct($annotationProvider, $noOpParametersProcessor); |
|
26
|
2 |
|
$this->decodeParametersProcessor = $decodeParametersProcessor; |
|
27
|
2 |
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
protected function getDecodeParametersProcessor(): ParametersProcessorInterface |
|
30
|
|
|
{ |
|
31
|
1 |
|
return $this->decodeParametersProcessor; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param object $controller |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function createControllerDecodeParametersProcessor($controller, string $method): ParametersProcessorInterface |
|
38
|
|
|
{ |
|
39
|
|
|
try { |
|
40
|
|
|
/** @var Hash $annotation */ |
|
41
|
2 |
|
$annotation = $this->getAnnotationProvider()->getFromObject( |
|
42
|
2 |
|
$controller, |
|
43
|
2 |
|
$method, |
|
44
|
2 |
|
Hash::class |
|
45
|
|
|
); |
|
46
|
1 |
|
} catch (InvalidControllerException | MissingClassOrMethodException $e) { |
|
47
|
1 |
|
$annotation = null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
return null !== $annotation |
|
51
|
1 |
|
? $this->getDecodeParametersProcessor()->setParametersToProcess($annotation->getParameters()) |
|
52
|
2 |
|
: $this->getNoOpParametersProcessor(); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|