CompiledRoute.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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(string $staticPrefix, string $regex, array $tokens, array $pathVariables, string $hostRegex = null, array $hostTokens = [], array $hostVariables = [], array $variables = [])
  37. {
  38. $this->staticPrefix = $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([
  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. $data = unserialize($serialized, ['allowed_classes' => false]);
  69. $this->variables = $data['vars'];
  70. $this->staticPrefix = $data['path_prefix'];
  71. $this->regex = $data['path_regex'];
  72. $this->tokens = $data['path_tokens'];
  73. $this->pathVariables = $data['path_vars'];
  74. $this->hostRegex = $data['host_regex'];
  75. $this->hostTokens = $data['host_tokens'];
  76. $this->hostVariables = $data['host_vars'];
  77. }
  78. /**
  79. * Returns the static prefix.
  80. *
  81. * @return string The static prefix
  82. */
  83. public function getStaticPrefix()
  84. {
  85. return $this->staticPrefix;
  86. }
  87. /**
  88. * Returns the regex.
  89. *
  90. * @return string The regex
  91. */
  92. public function getRegex()
  93. {
  94. return $this->regex;
  95. }
  96. /**
  97. * Returns the host regex.
  98. *
  99. * @return string|null The host regex or null
  100. */
  101. public function getHostRegex()
  102. {
  103. return $this->hostRegex;
  104. }
  105. /**
  106. * Returns the tokens.
  107. *
  108. * @return array The tokens
  109. */
  110. public function getTokens()
  111. {
  112. return $this->tokens;
  113. }
  114. /**
  115. * Returns the host tokens.
  116. *
  117. * @return array The tokens
  118. */
  119. public function getHostTokens()
  120. {
  121. return $this->hostTokens;
  122. }
  123. /**
  124. * Returns the variables.
  125. *
  126. * @return array The variables
  127. */
  128. public function getVariables()
  129. {
  130. return $this->variables;
  131. }
  132. /**
  133. * Returns the path variables.
  134. *
  135. * @return array The variables
  136. */
  137. public function getPathVariables()
  138. {
  139. return $this->pathVariables;
  140. }
  141. /**
  142. * Returns the host variables.
  143. *
  144. * @return array The variables
  145. */
  146. public function getHostVariables()
  147. {
  148. return $this->hostVariables;
  149. }
  150. }