blob: 0bec8930bab43a816884f2bf0e8fa3382ad2e75e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Default object for current_route_match service.
*/
class CurrentRouteMatch implements ResettableStackedRouteMatchInterface {
/**
* The related request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Internal cache of RouteMatch objects.
*
* @var \SplObjectStorage
*/
protected $routeMatches;
/**
* Constructs a CurrentRouteMatch object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
$this->routeMatches = new \SplObjectStorage();
}
/**
* {@inheritdoc}
*/
public function getRouteName() {
return $this->getCurrentRouteMatch()->getRouteName();
}
/**
* {@inheritdoc}
*/
public function getRouteObject() {
return $this->getCurrentRouteMatch()->getRouteObject();
}
/**
* {@inheritdoc}
*/
public function getParameter($parameter_name) {
return $this->getCurrentRouteMatch()->getParameter($parameter_name);
}
/**
* {@inheritdoc}
*/
public function getParameters() {
return $this->getCurrentRouteMatch()->getParameters();
}
/**
* {@inheritdoc}
*/
public function getRawParameter($parameter_name) {
return $this->getCurrentRouteMatch()->getRawParameter($parameter_name);
}
/**
* {@inheritdoc}
*/
public function getRawParameters() {
return $this->getCurrentRouteMatch()->getRawParameters();
}
/**
* Returns the route match for the current request.
*
* @return \Drupal\Core\Routing\RouteMatchInterface
* The current route match object.
*/
public function getCurrentRouteMatch() {
return $this->getRouteMatch($this->requestStack->getCurrentRequest());
}
/**
* Returns the route match for a passed in request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* A request object.
*
* @return \Drupal\Core\Routing\RouteMatchInterface
* A route match object created from the request.
*/
protected function getRouteMatch(Request $request) {
if (isset($this->routeMatches[$request])) {
$route_match = $this->routeMatches[$request];
}
else {
$route_match = RouteMatch::createFromRequest($request);
// Since getRouteMatch() might be invoked both before and after routing
// is completed, only statically cache the route match after there's a
// matched route.
if ($route_match->getRouteObject()) {
$this->routeMatches[$request] = $route_match;
}
}
return $route_match;
}
/**
* {@inheritdoc}
*/
public function resetRouteMatch() {
$this->routeMatches = new \SplObjectStorage();
}
/**
* {@inheritdoc}
*/
public function getMasterRouteMatch() {
return $this->getRouteMatch($this->requestStack->getMainRequest());
}
/**
* {@inheritdoc}
*/
public function getParentRouteMatch() {
return $this->getRouteMatch($this->requestStack->getParentRequest());
}
/**
* {@inheritdoc}
*/
public function getRouteMatchFromRequest(Request $request) {
return $this->getRouteMatch($request);
}
}
|