CompiledRoute.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * @internal
  62. */
  63. final public function serialize(): string
  64. {
  65. return serialize($this->__serialize());
  66. }
  67. public function __unserialize(array $data): void
  68. {
  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. * @internal
  80. */
  81. final public function unserialize($serialized)
  82. {
  83. $this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
  84. }
  85. /**
  86. * Returns the static prefix.
  87. *
  88. * @return string The static prefix
  89. */
  90. public function getStaticPrefix()
  91. {
  92. return $this->staticPrefix;
  93. }
  94. /**
  95. * Returns the regex.
  96. *
  97. * @return string The regex
  98. */
  99. public function getRegex()
  100. {
  101. return $this->regex;
  102. }
  103. /**
  104. * Returns the host regex.
  105. *
  106. * @return string|null The host regex or null
  107. */
  108. public function getHostRegex()
  109. {
  110. return $this->hostRegex;
  111. }
  112. /**
  113. * Returns the tokens.
  114. *
  115. * @return array The tokens
  116. */
  117. public function getTokens()
  118. {
  119. return $this->tokens;
  120. }
  121. /**
  122. * Returns the host tokens.
  123. *
  124. * @return array The tokens
  125. */
  126. public function getHostTokens()
  127. {
  128. return $this->hostTokens;
  129. }
  130. /**
  131. * Returns the variables.
  132. *
  133. * @return array The variables
  134. */
  135. public function getVariables()
  136. {
  137. return $this->variables;
  138. }
  139. /**
  140. * Returns the path variables.
  141. *
  142. * @return array The variables
  143. */
  144. public function getPathVariables()
  145. {
  146. return $this->pathVariables;
  147. }
  148. /**
  149. * Returns the host variables.
  150. *
  151. * @return array The variables
  152. */
  153. public function getHostVariables()
  154. {
  155. return $this->hostVariables;
  156. }
  157. }