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