4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing;
15 * CompiledRoutes are returned by the RouteCompiler class.
17 * @author Fabien Potencier <fabien@symfony.com>
19 class CompiledRoute implements \Serializable
23 private $staticPrefix;
25 private $pathVariables;
26 private $hostVariables;
31 * @param string $staticPrefix The static prefix of the compiled route
32 * @param string $regex The regular expression to use to match this route
33 * @param array $tokens An array of tokens to use to generate URL for this route
34 * @param array $pathVariables An array of path variables
35 * @param string|null $hostRegex Host regex
36 * @param array $hostTokens Host tokens
37 * @param array $hostVariables An array of host variables
38 * @param array $variables An array of variables (variables defined in the path and in the host patterns)
40 public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = null, array $hostTokens = array(), array $hostVariables = array(), array $variables = array())
42 $this->staticPrefix = (string) $staticPrefix;
43 $this->regex = $regex;
44 $this->tokens = $tokens;
45 $this->pathVariables = $pathVariables;
46 $this->hostRegex = $hostRegex;
47 $this->hostTokens = $hostTokens;
48 $this->hostVariables = $hostVariables;
49 $this->variables = $variables;
55 public function serialize()
57 return serialize(array(
58 'vars' => $this->variables,
59 'path_prefix' => $this->staticPrefix,
60 'path_regex' => $this->regex,
61 'path_tokens' => $this->tokens,
62 'path_vars' => $this->pathVariables,
63 'host_regex' => $this->hostRegex,
64 'host_tokens' => $this->hostTokens,
65 'host_vars' => $this->hostVariables,
72 public function unserialize($serialized)
74 if (\PHP_VERSION_ID >= 70000) {
75 $data = unserialize($serialized, array('allowed_classes' => false));
77 $data = unserialize($serialized);
80 $this->variables = $data['vars'];
81 $this->staticPrefix = $data['path_prefix'];
82 $this->regex = $data['path_regex'];
83 $this->tokens = $data['path_tokens'];
84 $this->pathVariables = $data['path_vars'];
85 $this->hostRegex = $data['host_regex'];
86 $this->hostTokens = $data['host_tokens'];
87 $this->hostVariables = $data['host_vars'];
91 * Returns the static prefix.
93 * @return string The static prefix
95 public function getStaticPrefix()
97 return $this->staticPrefix;
103 * @return string The regex
105 public function getRegex()
111 * Returns the host regex.
113 * @return string|null The host regex or null
115 public function getHostRegex()
117 return $this->hostRegex;
121 * Returns the tokens.
123 * @return array The tokens
125 public function getTokens()
127 return $this->tokens;
131 * Returns the host tokens.
133 * @return array The tokens
135 public function getHostTokens()
137 return $this->hostTokens;
141 * Returns the variables.
143 * @return array The variables
145 public function getVariables()
147 return $this->variables;
151 * Returns the path variables.
153 * @return array The variables
155 public function getPathVariables()
157 return $this->pathVariables;
161 * Returns the host variables.
163 * @return array The variables
165 public function getHostVariables()
167 return $this->hostVariables;