1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\controller_annotations\Routing; |
4
|
|
|
|
5
|
|
|
use Drupal\controller_annotations\Configuration\RouteModifierClassInterface; |
6
|
|
|
use Drupal\controller_annotations\Configuration\RouteModifierMethodInterface; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Routing\AnnotatedRouteControllerLoader as BaseAnnotatedRouteControllerLoader; |
8
|
|
|
use Symfony\Component\Routing\Route; |
9
|
|
|
|
10
|
|
|
class AnnotatedRouteControllerLoader extends BaseAnnotatedRouteControllerLoader |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param Route $route |
14
|
|
|
* @param \ReflectionClass $class |
15
|
|
|
* @param \ReflectionMethod $method |
16
|
|
|
* @param mixed $annotation |
17
|
|
|
*/ |
18
|
6 |
|
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation) |
19
|
|
|
{ |
20
|
6 |
|
$this->setController($route, $class, $method); |
21
|
6 |
|
$this->configureClassAnnotations($route, $class, $method); |
22
|
6 |
|
$this->configureMethodAnnotations($route, $class, $method); |
23
|
6 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Route $route |
27
|
|
|
* @param \ReflectionClass $class |
28
|
|
|
* @param \ReflectionMethod $method |
29
|
|
|
*/ |
30
|
6 |
|
protected function configureClassAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) |
31
|
|
|
{ |
32
|
6 |
|
foreach ($this->reader->getClassAnnotations($class) as $configuration) { |
33
|
5 |
|
if ($configuration instanceof RouteModifierClassInterface) { |
34
|
5 |
|
$configuration->modifyRouteClass($route, $class, $method); |
35
|
|
|
} |
36
|
|
|
} |
37
|
6 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Route $route |
41
|
|
|
* @param \ReflectionClass $class |
42
|
|
|
* @param \ReflectionMethod $method |
43
|
|
|
*/ |
44
|
6 |
|
protected function configureMethodAnnotations(Route $route, \ReflectionClass $class, \ReflectionMethod $method) |
45
|
|
|
{ |
46
|
6 |
|
foreach ($this->reader->getMethodAnnotations($method) as $configuration) { |
47
|
6 |
|
if ($configuration instanceof RouteModifierMethodInterface) { |
48
|
6 |
|
$configuration->modifyRouteMethod($route, $class, $method); |
49
|
|
|
} |
50
|
|
|
} |
51
|
6 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Route $route |
55
|
|
|
* @param \ReflectionClass $class |
56
|
|
|
* @param \ReflectionMethod $method |
57
|
|
|
*/ |
58
|
6 |
|
protected function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) |
59
|
|
|
{ |
60
|
6 |
|
$route->setDefault('_controller', $this->getControllerName($class, $method)); |
61
|
6 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \ReflectionClass $class |
65
|
|
|
* @param \ReflectionMethod $method |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
6 |
|
protected function getControllerName(\ReflectionClass $class, \ReflectionMethod $method) |
69
|
|
|
{ |
70
|
6 |
|
$annotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); |
71
|
6 |
|
if ($annotation instanceof \Drupal\controller_annotations\Configuration\Route && $service = $annotation->getService()) { |
72
|
5 |
|
return sprintf('%s:%s', $service, $method->getName()); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
6 |
|
return sprintf('%s::%s', $class->getName(), $method->getName()); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|