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