Ei kuvausta

CompiledRoute.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. public function __serialize(): array
  48. {
  49. return [
  50. 'vars' => $this->variables,
  51. 'path_prefix' => $this->staticPrefix,
  52. 'path_regex' => $this->regex,
  53. 'path_tokens' => $this->tokens,
  54. 'path_vars' => $this->pathVariables,
  55. 'host_regex' => $this->hostRegex,
  56. 'host_tokens' => $this->hostTokens,
  57. 'host_vars' => $this->hostVariables,
  58. ];
  59. }
  60. /**
  61. * @return string
  62. *
  63. * @internal since Symfony 4.3
  64. * @final since Symfony 4.3
  65. */
  66. public function serialize()
  67. {
  68. return serialize($this->__serialize());
  69. }
  70. public function __unserialize(array $data): void
  71. {
  72. $this->variables = $data['vars'];
  73. $this->staticPrefix = $data['path_prefix'];
  74. $this->regex = $data['path_regex'];
  75. $this->tokens = $data['path_tokens'];
  76. $this->pathVariables = $data['path_vars'];
  77. $this->hostRegex = $data['host_regex'];
  78. $this->hostTokens = $data['host_tokens'];
  79. $this->hostVariables = $data['host_vars'];
  80. }
  81. /**
  82. * @internal since Symfony 4.3
  83. * @final since Symfony 4.3
  84. */
  85. public function unserialize($serialized)
  86. {
  87. $this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
  88. }
  89. /**
  90. * Returns the static prefix.
  91. *
  92. * @return string The static prefix
  93. */
  94. public function getStaticPrefix()
  95. {
  96. return $this->staticPrefix;
  97. }
  98. /**
  99. * Returns the regex.
  100. *
  101. * @return string The regex
  102. */
  103. public function getRegex()
  104. {
  105. return $this->regex;
  106. }
  107. /**
  108. * Returns the host regex.
  109. *
  110. * @return string|null The host regex or null
  111. */
  112. public function getHostRegex()
  113. {
  114. return $this->hostRegex;
  115. }
  116. /**
  117. * Returns the tokens.
  118. *
  119. * @return array The tokens
  120. */
  121. public function getTokens()
  122. {
  123. return $this->tokens;
  124. }
  125. /**
  126. * Returns the host tokens.
  127. *
  128. * @return array The tokens
  129. */
  130. public function getHostTokens()
  131. {
  132. return $this->hostTokens;
  133. }
  134. /**
  135. * Returns the variables.
  136. *
  137. * @return array The variables
  138. */
  139. public function getVariables()
  140. {
  141. return $this->variables;
  142. }
  143. /**
  144. * Returns the path variables.
  145. *
  146. * @return array The variables
  147. */
  148. public function getPathVariables()
  149. {
  150. return $this->pathVariables;
  151. }
  152. /**
  153. * Returns the host variables.
  154. *
  155. * @return array The variables
  156. */
  157. public function getHostVariables()
  158. {
  159. return $this->hostVariables;
  160. }
  161. }