Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Routing;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Unicode;
|
Chris@0
|
6 use Symfony\Component\Routing\CompiledRoute as SymfonyCompiledRoute;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * A compiled route contains derived information from a route object.
|
Chris@0
|
10 */
|
Chris@0
|
11 class CompiledRoute extends SymfonyCompiledRoute {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * The fitness of this route.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @var int
|
Chris@0
|
17 */
|
Chris@0
|
18 protected $fit;
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * The pattern outline of this route.
|
Chris@0
|
22 *
|
Chris@0
|
23 * @var string
|
Chris@0
|
24 */
|
Chris@0
|
25 protected $patternOutline;
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * The number of parts in the path of this route.
|
Chris@0
|
29 *
|
Chris@0
|
30 * @var int
|
Chris@0
|
31 */
|
Chris@0
|
32 protected $numParts;
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Constructs a new compiled route object.
|
Chris@0
|
36 *
|
Chris@0
|
37 * This is a ridiculously long set of constructor parameters, but as this
|
Chris@0
|
38 * object is little more than a collection of values it's not a serious
|
Chris@0
|
39 * problem. The parent Symfony class does the same, as well, making it
|
Chris@0
|
40 * difficult to override differently.
|
Chris@0
|
41 *
|
Chris@0
|
42 * @param int $fit
|
Chris@0
|
43 * The fitness of the route.
|
Chris@0
|
44 * @param string $pattern_outline
|
Chris@0
|
45 * The pattern outline for this route.
|
Chris@0
|
46 * @param int $num_parts
|
Chris@0
|
47 * The number of parts in the path.
|
Chris@0
|
48 * @param string $staticPrefix
|
Chris@0
|
49 * The static prefix of the compiled route
|
Chris@0
|
50 * @param string $regex
|
Chris@0
|
51 * The regular expression to use to match this route
|
Chris@0
|
52 * @param array $tokens
|
Chris@0
|
53 * An array of tokens to use to generate URL for this route
|
Chris@0
|
54 * @param array $pathVariables
|
Chris@0
|
55 * An array of path variables
|
Chris@0
|
56 * @param string|null $hostRegex
|
Chris@0
|
57 * Host regex
|
Chris@0
|
58 * @param array $hostTokens
|
Chris@0
|
59 * Host tokens
|
Chris@0
|
60 * @param array $hostVariables
|
Chris@0
|
61 * An array of host variables
|
Chris@0
|
62 * @param array $variables
|
Chris@0
|
63 * An array of variables (variables defined in the path and in the host patterns)
|
Chris@0
|
64 */
|
Chris@0
|
65 public function __construct($fit, $pattern_outline, $num_parts, $staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = NULL, array $hostTokens = [], array $hostVariables = [], array $variables = []) {
|
Chris@0
|
66 parent::__construct($staticPrefix, $regex, $tokens, $pathVariables, $hostRegex, $hostTokens, $hostVariables, $variables);
|
Chris@0
|
67
|
Chris@0
|
68 $this->fit = $fit;
|
Chris@0
|
69 // Support case-insensitive route matching by ensuring the pattern outline
|
Chris@0
|
70 // is lowercase.
|
Chris@0
|
71 // @see \Drupal\Core\Routing\RouteProvider::getRoutesByPath()
|
Chris@0
|
72 $this->patternOutline = Unicode::strtolower($pattern_outline);
|
Chris@0
|
73 $this->numParts = $num_parts;
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 /**
|
Chris@0
|
77 * Returns the fit of this route.
|
Chris@0
|
78 *
|
Chris@0
|
79 * See RouteCompiler for a definition of how the fit is calculated.
|
Chris@0
|
80 *
|
Chris@0
|
81 * @return int
|
Chris@0
|
82 * The fit of the route.
|
Chris@0
|
83 */
|
Chris@0
|
84 public function getFit() {
|
Chris@0
|
85 return $this->fit;
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@0
|
88 /**
|
Chris@0
|
89 * Returns the number of parts in this route's path.
|
Chris@0
|
90 *
|
Chris@0
|
91 * The string "foo/bar/baz" has 3 parts, regardless of how many of them are
|
Chris@0
|
92 * placeholders.
|
Chris@0
|
93 *
|
Chris@0
|
94 * @return int
|
Chris@0
|
95 * The number of parts in the path.
|
Chris@0
|
96 */
|
Chris@0
|
97 public function getNumParts() {
|
Chris@0
|
98 return $this->numParts;
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Returns the pattern outline of this route.
|
Chris@0
|
103 *
|
Chris@0
|
104 * The pattern outline of a route is the path pattern of the route, but
|
Chris@0
|
105 * normalized such that all placeholders are replaced with %.
|
Chris@0
|
106 *
|
Chris@0
|
107 * @return string
|
Chris@0
|
108 * The normalized path pattern.
|
Chris@0
|
109 */
|
Chris@0
|
110 public function getPatternOutline() {
|
Chris@0
|
111 return $this->patternOutline;
|
Chris@0
|
112 }
|
Chris@0
|
113
|
Chris@0
|
114 /**
|
Chris@0
|
115 * Returns the options.
|
Chris@0
|
116 *
|
Chris@0
|
117 * @return array
|
Chris@0
|
118 * The options.
|
Chris@0
|
119 */
|
Chris@0
|
120 public function getOptions() {
|
Chris@0
|
121 return $this->route->getOptions();
|
Chris@0
|
122 }
|
Chris@0
|
123
|
Chris@0
|
124 /**
|
Chris@0
|
125 * Returns the defaults.
|
Chris@0
|
126 *
|
Chris@0
|
127 * @return array
|
Chris@0
|
128 * The defaults.
|
Chris@0
|
129 */
|
Chris@0
|
130 public function getDefaults() {
|
Chris@0
|
131 return $this->route->getDefaults();
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@0
|
134 /**
|
Chris@0
|
135 * Returns the requirements.
|
Chris@0
|
136 *
|
Chris@0
|
137 * @return array
|
Chris@0
|
138 * The requirements.
|
Chris@0
|
139 */
|
Chris@0
|
140 public function getRequirements() {
|
Chris@0
|
141 return $this->route->getRequirements();
|
Chris@0
|
142 }
|
Chris@0
|
143
|
Chris@0
|
144 /**
|
Chris@0
|
145 * {@inheritdoc}
|
Chris@0
|
146 */
|
Chris@0
|
147 public function serialize() {
|
Chris@0
|
148 // Calling the parent method is safer than trying to optimize out the extra
|
Chris@0
|
149 // function calls.
|
Chris@0
|
150 $data = unserialize(parent::serialize());
|
Chris@0
|
151 $data['fit'] = $this->fit;
|
Chris@0
|
152 $data['patternOutline'] = $this->patternOutline;
|
Chris@0
|
153 $data['numParts'] = $this->numParts;
|
Chris@0
|
154
|
Chris@0
|
155 return serialize($data);
|
Chris@0
|
156 }
|
Chris@0
|
157
|
Chris@0
|
158 /**
|
Chris@0
|
159 * {@inheritdoc}
|
Chris@0
|
160 */
|
Chris@0
|
161 public function unserialize($serialized) {
|
Chris@0
|
162 parent::unserialize($serialized);
|
Chris@0
|
163 $data = unserialize($serialized);
|
Chris@0
|
164
|
Chris@0
|
165 $this->fit = $data['fit'];
|
Chris@0
|
166 $this->patternOutline = $data['patternOutline'];
|
Chris@0
|
167 $this->numParts = $data['numParts'];
|
Chris@0
|
168 }
|
Chris@0
|
169
|
Chris@0
|
170 }
|