CompiledRoute.php 4.3 KB

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