菜谱项目

CompiledRoute.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * @param string $staticPrefix The static prefix of the compiled route
  28. * @param string $regex The regular expression to use to match this route
  29. * @param array $tokens An array of tokens to use to generate URL for this route
  30. * @param array $pathVariables An array of path variables
  31. * @param string|null $hostRegex Host regex
  32. * @param array $hostTokens Host tokens
  33. * @param array $hostVariables An array of host variables
  34. * @param array $variables An array of variables (variables defined in the path and in the host patterns)
  35. */
  36. public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = null, array $hostTokens = array(), array $hostVariables = array(), array $variables = array())
  37. {
  38. $this->staticPrefix = (string) $staticPrefix;
  39. $this->regex = $regex;
  40. $this->tokens = $tokens;
  41. $this->pathVariables = $pathVariables;
  42. $this->hostRegex = $hostRegex;
  43. $this->hostTokens = $hostTokens;
  44. $this->hostVariables = $hostVariables;
  45. $this->variables = $variables;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function serialize()
  51. {
  52. return serialize(array(
  53. 'vars' => $this->variables,
  54. 'path_prefix' => $this->staticPrefix,
  55. 'path_regex' => $this->regex,
  56. 'path_tokens' => $this->tokens,
  57. 'path_vars' => $this->pathVariables,
  58. 'host_regex' => $this->hostRegex,
  59. 'host_tokens' => $this->hostTokens,
  60. 'host_vars' => $this->hostVariables,
  61. ));
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function unserialize($serialized)
  67. {
  68. if (\PHP_VERSION_ID >= 70000) {
  69. $data = unserialize($serialized, array('allowed_classes' => false));
  70. } else {
  71. $data = unserialize($serialized);
  72. }
  73. $this->variables = $data['vars'];
  74. $this->staticPrefix = $data['path_prefix'];
  75. $this->regex = $data['path_regex'];
  76. $this->tokens = $data['path_tokens'];
  77. $this->pathVariables = $data['path_vars'];
  78. $this->hostRegex = $data['host_regex'];
  79. $this->hostTokens = $data['host_tokens'];
  80. $this->hostVariables = $data['host_vars'];
  81. }
  82. /**
  83. * Returns the static prefix.
  84. *
  85. * @return string The static prefix
  86. */
  87. public function getStaticPrefix()
  88. {
  89. return $this->staticPrefix;
  90. }
  91. /**
  92. * Returns the regex.
  93. *
  94. * @return string The regex
  95. */
  96. public function getRegex()
  97. {
  98. return $this->regex;
  99. }
  100. /**
  101. * Returns the host regex.
  102. *
  103. * @return string|null The host regex or null
  104. */
  105. public function getHostRegex()
  106. {
  107. return $this->hostRegex;
  108. }
  109. /**
  110. * Returns the tokens.
  111. *
  112. * @return array The tokens
  113. */
  114. public function getTokens()
  115. {
  116. return $this->tokens;
  117. }
  118. /**
  119. * Returns the host tokens.
  120. *
  121. * @return array The tokens
  122. */
  123. public function getHostTokens()
  124. {
  125. return $this->hostTokens;
  126. }
  127. /**
  128. * Returns the variables.
  129. *
  130. * @return array The variables
  131. */
  132. public function getVariables()
  133. {
  134. return $this->variables;
  135. }
  136. /**
  137. * Returns the path variables.
  138. *
  139. * @return array The variables
  140. */
  141. public function getPathVariables()
  142. {
  143. return $this->pathVariables;
  144. }
  145. /**
  146. * Returns the host variables.
  147. *
  148. * @return array The variables
  149. */
  150. public function getHostVariables()
  151. {
  152. return $this->hostVariables;
  153. }
  154. }