Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Routing;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * CompiledRoutes are returned by the RouteCompiler class.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
18 */
|
Chris@0
|
19 class CompiledRoute implements \Serializable
|
Chris@0
|
20 {
|
Chris@0
|
21 private $variables;
|
Chris@0
|
22 private $tokens;
|
Chris@0
|
23 private $staticPrefix;
|
Chris@0
|
24 private $regex;
|
Chris@0
|
25 private $pathVariables;
|
Chris@0
|
26 private $hostVariables;
|
Chris@0
|
27 private $hostRegex;
|
Chris@0
|
28 private $hostTokens;
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * @param string $staticPrefix The static prefix of the compiled route
|
Chris@0
|
32 * @param string $regex The regular expression to use to match this route
|
Chris@0
|
33 * @param array $tokens An array of tokens to use to generate URL for this route
|
Chris@0
|
34 * @param array $pathVariables An array of path variables
|
Chris@0
|
35 * @param string|null $hostRegex Host regex
|
Chris@0
|
36 * @param array $hostTokens Host tokens
|
Chris@0
|
37 * @param array $hostVariables An array of host variables
|
Chris@0
|
38 * @param array $variables An array of variables (variables defined in the path and in the host patterns)
|
Chris@0
|
39 */
|
Chris@17
|
40 public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = null, array $hostTokens = [], array $hostVariables = [], array $variables = [])
|
Chris@0
|
41 {
|
Chris@0
|
42 $this->staticPrefix = (string) $staticPrefix;
|
Chris@0
|
43 $this->regex = $regex;
|
Chris@0
|
44 $this->tokens = $tokens;
|
Chris@0
|
45 $this->pathVariables = $pathVariables;
|
Chris@0
|
46 $this->hostRegex = $hostRegex;
|
Chris@0
|
47 $this->hostTokens = $hostTokens;
|
Chris@0
|
48 $this->hostVariables = $hostVariables;
|
Chris@0
|
49 $this->variables = $variables;
|
Chris@0
|
50 }
|
Chris@0
|
51
|
Chris@0
|
52 /**
|
Chris@0
|
53 * {@inheritdoc}
|
Chris@0
|
54 */
|
Chris@0
|
55 public function serialize()
|
Chris@0
|
56 {
|
Chris@17
|
57 return serialize([
|
Chris@0
|
58 'vars' => $this->variables,
|
Chris@0
|
59 'path_prefix' => $this->staticPrefix,
|
Chris@0
|
60 'path_regex' => $this->regex,
|
Chris@0
|
61 'path_tokens' => $this->tokens,
|
Chris@0
|
62 'path_vars' => $this->pathVariables,
|
Chris@0
|
63 'host_regex' => $this->hostRegex,
|
Chris@0
|
64 'host_tokens' => $this->hostTokens,
|
Chris@0
|
65 'host_vars' => $this->hostVariables,
|
Chris@17
|
66 ]);
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * {@inheritdoc}
|
Chris@0
|
71 */
|
Chris@0
|
72 public function unserialize($serialized)
|
Chris@0
|
73 {
|
Chris@14
|
74 if (\PHP_VERSION_ID >= 70000) {
|
Chris@17
|
75 $data = unserialize($serialized, ['allowed_classes' => false]);
|
Chris@14
|
76 } else {
|
Chris@14
|
77 $data = unserialize($serialized);
|
Chris@14
|
78 }
|
Chris@14
|
79
|
Chris@0
|
80 $this->variables = $data['vars'];
|
Chris@0
|
81 $this->staticPrefix = $data['path_prefix'];
|
Chris@0
|
82 $this->regex = $data['path_regex'];
|
Chris@0
|
83 $this->tokens = $data['path_tokens'];
|
Chris@0
|
84 $this->pathVariables = $data['path_vars'];
|
Chris@0
|
85 $this->hostRegex = $data['host_regex'];
|
Chris@0
|
86 $this->hostTokens = $data['host_tokens'];
|
Chris@0
|
87 $this->hostVariables = $data['host_vars'];
|
Chris@0
|
88 }
|
Chris@0
|
89
|
Chris@0
|
90 /**
|
Chris@0
|
91 * Returns the static prefix.
|
Chris@0
|
92 *
|
Chris@0
|
93 * @return string The static prefix
|
Chris@0
|
94 */
|
Chris@0
|
95 public function getStaticPrefix()
|
Chris@0
|
96 {
|
Chris@0
|
97 return $this->staticPrefix;
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * Returns the regex.
|
Chris@0
|
102 *
|
Chris@0
|
103 * @return string The regex
|
Chris@0
|
104 */
|
Chris@0
|
105 public function getRegex()
|
Chris@0
|
106 {
|
Chris@0
|
107 return $this->regex;
|
Chris@0
|
108 }
|
Chris@0
|
109
|
Chris@0
|
110 /**
|
Chris@0
|
111 * Returns the host regex.
|
Chris@0
|
112 *
|
Chris@0
|
113 * @return string|null The host regex or null
|
Chris@0
|
114 */
|
Chris@0
|
115 public function getHostRegex()
|
Chris@0
|
116 {
|
Chris@0
|
117 return $this->hostRegex;
|
Chris@0
|
118 }
|
Chris@0
|
119
|
Chris@0
|
120 /**
|
Chris@0
|
121 * Returns the tokens.
|
Chris@0
|
122 *
|
Chris@0
|
123 * @return array The tokens
|
Chris@0
|
124 */
|
Chris@0
|
125 public function getTokens()
|
Chris@0
|
126 {
|
Chris@0
|
127 return $this->tokens;
|
Chris@0
|
128 }
|
Chris@0
|
129
|
Chris@0
|
130 /**
|
Chris@0
|
131 * Returns the host tokens.
|
Chris@0
|
132 *
|
Chris@0
|
133 * @return array The tokens
|
Chris@0
|
134 */
|
Chris@0
|
135 public function getHostTokens()
|
Chris@0
|
136 {
|
Chris@0
|
137 return $this->hostTokens;
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 /**
|
Chris@0
|
141 * Returns the variables.
|
Chris@0
|
142 *
|
Chris@0
|
143 * @return array The variables
|
Chris@0
|
144 */
|
Chris@0
|
145 public function getVariables()
|
Chris@0
|
146 {
|
Chris@0
|
147 return $this->variables;
|
Chris@0
|
148 }
|
Chris@0
|
149
|
Chris@0
|
150 /**
|
Chris@0
|
151 * Returns the path variables.
|
Chris@0
|
152 *
|
Chris@0
|
153 * @return array The variables
|
Chris@0
|
154 */
|
Chris@0
|
155 public function getPathVariables()
|
Chris@0
|
156 {
|
Chris@0
|
157 return $this->pathVariables;
|
Chris@0
|
158 }
|
Chris@0
|
159
|
Chris@0
|
160 /**
|
Chris@0
|
161 * Returns the host variables.
|
Chris@0
|
162 *
|
Chris@0
|
163 * @return array The variables
|
Chris@0
|
164 */
|
Chris@0
|
165 public function getHostVariables()
|
Chris@0
|
166 {
|
Chris@0
|
167 return $this->hostVariables;
|
Chris@0
|
168 }
|
Chris@0
|
169 }
|