1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\controller_annotations\Configuration; |
4
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route as BaseRoute; |
6
|
|
|
use Symfony\Component\Routing\Route as RoutingRoute; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @Annotation |
10
|
|
|
*/ |
11
|
|
|
class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModifierClassInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var bool |
15
|
|
|
*/ |
16
|
|
|
protected $admin; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
8 |
|
public function isAdmin() |
22
|
|
|
{ |
23
|
8 |
|
return $this->admin; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param bool $admin |
28
|
|
|
* @return Route |
29
|
|
|
*/ |
30
|
7 |
|
public function setAdmin($admin) |
31
|
|
|
{ |
32
|
7 |
|
$this->admin = $admin; |
33
|
|
|
|
34
|
7 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param RoutingRoute $route |
39
|
|
|
* @param \ReflectionClass $class |
40
|
|
|
* @param \ReflectionMethod $method |
41
|
|
|
*/ |
42
|
7 |
|
public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) |
43
|
|
|
{ |
44
|
7 |
|
$this->modifyRoute($route, $class, $method); |
45
|
7 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param RoutingRoute $route |
49
|
|
|
* @param \ReflectionClass $class |
50
|
|
|
* @param \ReflectionMethod $method |
51
|
|
|
*/ |
52
|
8 |
|
public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) |
53
|
|
|
{ |
54
|
8 |
|
if ($this->getService()) { |
55
|
1 |
|
throw new \LogicException('The service option can only be specified at class level.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
7 |
|
$this->modifyRoute($route, $class, $method); |
59
|
7 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param RoutingRoute $route |
63
|
|
|
* @param \ReflectionClass $class |
64
|
|
|
* @param \ReflectionMethod $method |
65
|
|
|
*/ |
66
|
8 |
|
protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method) |
|
|
|
|
67
|
|
|
{ |
68
|
8 |
|
if ($this->isAdmin()) { |
69
|
7 |
|
$route->setOption('_admin_route', true); |
70
|
|
|
} |
71
|
8 |
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.