Route.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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\Attribute;
  11. /**
  12. * Annotation class for @Route().
  13. *
  14. * @Annotation
  15. * @NamedArgumentConstructor
  16. * @Target({"CLASS", "METHOD"})
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Alexander M. Turek <me@derrabus.de>
  20. */
  21. #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
  22. class Route
  23. {
  24. private ?string $path = null;
  25. private array $localizedPaths = [];
  26. private array $methods;
  27. private array $schemes;
  28. /**
  29. * @param array<string|\Stringable> $requirements
  30. * @param string[]|string $methods
  31. * @param string[]|string $schemes
  32. */
  33. public function __construct(
  34. string|array|null $path = null,
  35. private ?string $name = null,
  36. private array $requirements = [],
  37. private array $options = [],
  38. private array $defaults = [],
  39. private ?string $host = null,
  40. array|string $methods = [],
  41. array|string $schemes = [],
  42. private ?string $condition = null,
  43. private ?int $priority = null,
  44. ?string $locale = null,
  45. ?string $format = null,
  46. ?bool $utf8 = null,
  47. ?bool $stateless = null,
  48. private ?string $env = null,
  49. ) {
  50. if (\is_array($path)) {
  51. $this->localizedPaths = $path;
  52. } else {
  53. $this->path = $path;
  54. }
  55. $this->setMethods($methods);
  56. $this->setSchemes($schemes);
  57. if (null !== $locale) {
  58. $this->defaults['_locale'] = $locale;
  59. }
  60. if (null !== $format) {
  61. $this->defaults['_format'] = $format;
  62. }
  63. if (null !== $utf8) {
  64. $this->options['utf8'] = $utf8;
  65. }
  66. if (null !== $stateless) {
  67. $this->defaults['_stateless'] = $stateless;
  68. }
  69. }
  70. /**
  71. * @return void
  72. */
  73. public function setPath(string $path)
  74. {
  75. $this->path = $path;
  76. }
  77. /**
  78. * @return string|null
  79. */
  80. public function getPath()
  81. {
  82. return $this->path;
  83. }
  84. /**
  85. * @return void
  86. */
  87. public function setLocalizedPaths(array $localizedPaths)
  88. {
  89. $this->localizedPaths = $localizedPaths;
  90. }
  91. public function getLocalizedPaths(): array
  92. {
  93. return $this->localizedPaths;
  94. }
  95. /**
  96. * @return void
  97. */
  98. public function setHost(string $pattern)
  99. {
  100. $this->host = $pattern;
  101. }
  102. /**
  103. * @return string|null
  104. */
  105. public function getHost()
  106. {
  107. return $this->host;
  108. }
  109. /**
  110. * @return void
  111. */
  112. public function setName(string $name)
  113. {
  114. $this->name = $name;
  115. }
  116. /**
  117. * @return string|null
  118. */
  119. public function getName()
  120. {
  121. return $this->name;
  122. }
  123. /**
  124. * @return void
  125. */
  126. public function setRequirements(array $requirements)
  127. {
  128. $this->requirements = $requirements;
  129. }
  130. /**
  131. * @return array
  132. */
  133. public function getRequirements()
  134. {
  135. return $this->requirements;
  136. }
  137. /**
  138. * @return void
  139. */
  140. public function setOptions(array $options)
  141. {
  142. $this->options = $options;
  143. }
  144. /**
  145. * @return array
  146. */
  147. public function getOptions()
  148. {
  149. return $this->options;
  150. }
  151. /**
  152. * @return void
  153. */
  154. public function setDefaults(array $defaults)
  155. {
  156. $this->defaults = $defaults;
  157. }
  158. /**
  159. * @return array
  160. */
  161. public function getDefaults()
  162. {
  163. return $this->defaults;
  164. }
  165. /**
  166. * @return void
  167. */
  168. public function setSchemes(array|string $schemes)
  169. {
  170. $this->schemes = (array) $schemes;
  171. }
  172. /**
  173. * @return array
  174. */
  175. public function getSchemes()
  176. {
  177. return $this->schemes;
  178. }
  179. /**
  180. * @return void
  181. */
  182. public function setMethods(array|string $methods)
  183. {
  184. $this->methods = (array) $methods;
  185. }
  186. /**
  187. * @return array
  188. */
  189. public function getMethods()
  190. {
  191. return $this->methods;
  192. }
  193. /**
  194. * @return void
  195. */
  196. public function setCondition(?string $condition)
  197. {
  198. $this->condition = $condition;
  199. }
  200. /**
  201. * @return string|null
  202. */
  203. public function getCondition()
  204. {
  205. return $this->condition;
  206. }
  207. public function setPriority(int $priority): void
  208. {
  209. $this->priority = $priority;
  210. }
  211. public function getPriority(): ?int
  212. {
  213. return $this->priority;
  214. }
  215. public function setEnv(?string $env): void
  216. {
  217. $this->env = $env;
  218. }
  219. public function getEnv(): ?string
  220. {
  221. return $this->env;
  222. }
  223. }
  224. if (!class_exists(\Symfony\Component\Routing\Annotation\Route::class, false)) {
  225. class_alias(Route::class, \Symfony\Component\Routing\Annotation\Route::class);
  226. }