1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\controller_annotations\Routing; |
4
|
|
|
|
5
|
|
|
use Drupal\controller_annotations\Configuration\RouteModifierInterface; |
6
|
|
|
use Drupal\controller_annotations\Configuration\Route as RouteConfiguration; |
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); |
22
|
6 |
|
$this->configureMethodAnnotations($route, $method); |
23
|
6 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Route $route |
27
|
|
|
* @param \ReflectionClass $class |
28
|
|
|
*/ |
29
|
6 |
|
protected function configureClassAnnotations(Route $route, \ReflectionClass $class) |
30
|
|
|
{ |
31
|
6 |
|
foreach ($this->reader->getClassAnnotations($class) as $configuration) { |
32
|
5 |
|
if ($configuration instanceof RouteModifierInterface) { |
33
|
5 |
|
$configuration->modifyRoute($route); |
34
|
|
|
} |
35
|
|
|
} |
36
|
6 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Route $route |
40
|
|
|
* @param \ReflectionMethod $method |
41
|
|
|
*/ |
42
|
6 |
|
protected function configureMethodAnnotations(Route $route, \ReflectionMethod $method) |
43
|
|
|
{ |
44
|
6 |
|
foreach ($this->reader->getMethodAnnotations($method) as $configuration) { |
45
|
6 |
|
if ($configuration instanceof RouteModifierInterface) { |
46
|
6 |
|
$configuration->modifyRoute($route); |
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
if ($configuration instanceof RouteConfiguration && $configuration->getService()) { |
50
|
6 |
|
throw new \LogicException('The service option can only be specified at class level.'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
6 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Route $route |
57
|
|
|
* @param \ReflectionClass $class |
58
|
|
|
* @param \ReflectionMethod $method |
59
|
|
|
*/ |
60
|
6 |
|
private function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method) |
61
|
|
|
{ |
62
|
6 |
|
$classAnnotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass); |
63
|
6 |
|
if ($classAnnotation instanceof RouteConfiguration && $service = $classAnnotation->getService()) { |
64
|
5 |
|
$route->setDefault('_controller', $service . ':' . $method->getName()); |
|
|
|
|
65
|
|
|
} else { |
66
|
6 |
|
$route->setDefault('_controller', $class->getName() . '::' . $method->getName()); |
|
|
|
|
67
|
|
|
} |
68
|
6 |
|
} |
69
|
|
|
} |
70
|
|
|
|