|
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
|
|
|
use Symfony\Component\Routing\Route; |
|
13
|
|
|
|
|
14
|
|
|
class EncodeParametersProcessorFactory extends AbstractParametersProcessorFactory |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var ParametersProcessorInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $encodeParametersProcessor; |
|
20
|
|
|
|
|
21
|
3 |
|
public function __construct( |
|
22
|
|
|
AnnotationProvider $annotationProvider, |
|
23
|
|
|
ParametersProcessorInterface $noOpParametersProcessor, |
|
24
|
|
|
ParametersProcessorInterface $encodeParametersProcessor |
|
25
|
|
|
) { |
|
26
|
3 |
|
parent::__construct($annotationProvider, $noOpParametersProcessor); |
|
27
|
3 |
|
$this->encodeParametersProcessor = $encodeParametersProcessor; |
|
28
|
3 |
|
} |
|
29
|
|
|
|
|
30
|
3 |
|
public function createRouteEncodeParametersProcessor(Route $route) |
|
31
|
|
|
{ |
|
32
|
3 |
|
$controller = $route->getDefault('_controller'); |
|
33
|
|
|
try { |
|
34
|
|
|
/** @var Hash $annotation */ |
|
35
|
3 |
|
$annotation = $this->getAnnotationProvider()->getFromString($controller, Hash::class); |
|
36
|
1 |
|
} catch (InvalidControllerException | MissingClassOrMethodException $e) { |
|
37
|
1 |
|
$annotation = null; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
return null !== $annotation |
|
41
|
2 |
|
? $this->getEncodeParametersProcessor()->setParametersToProcess($annotation->getParameters()) |
|
42
|
3 |
|
: $this->getNoOpParametersProcessor(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
protected function getEncodeParametersProcessor(): ParametersProcessorInterface |
|
46
|
|
|
{ |
|
47
|
2 |
|
return $this->encodeParametersProcessor; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|