Route.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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\Annotation;
  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 string[] $requirements
  30. * @param string[]|string $methods
  31. * @param string[]|string $schemes
  32. */
  33. public function __construct(
  34. string|array $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. public function setPath(string $path)
  71. {
  72. $this->path = $path;
  73. }
  74. public function getPath()
  75. {
  76. return $this->path;
  77. }
  78. public function setLocalizedPaths(array $localizedPaths)
  79. {
  80. $this->localizedPaths = $localizedPaths;
  81. }
  82. public function getLocalizedPaths(): array
  83. {
  84. return $this->localizedPaths;
  85. }
  86. public function setHost(string $pattern)
  87. {
  88. $this->host = $pattern;
  89. }
  90. public function getHost()
  91. {
  92. return $this->host;
  93. }
  94. public function setName(string $name)
  95. {
  96. $this->name = $name;
  97. }
  98. public function getName()
  99. {
  100. return $this->name;
  101. }
  102. public function setRequirements(array $requirements)
  103. {
  104. $this->requirements = $requirements;
  105. }
  106. public function getRequirements()
  107. {
  108. return $this->requirements;
  109. }
  110. public function setOptions(array $options)
  111. {
  112. $this->options = $options;
  113. }
  114. public function getOptions()
  115. {
  116. return $this->options;
  117. }
  118. public function setDefaults(array $defaults)
  119. {
  120. $this->defaults = $defaults;
  121. }
  122. public function getDefaults()
  123. {
  124. return $this->defaults;
  125. }
  126. public function setSchemes(array|string $schemes)
  127. {
  128. $this->schemes = (array) $schemes;
  129. }
  130. public function getSchemes()
  131. {
  132. return $this->schemes;
  133. }
  134. public function setMethods(array|string $methods)
  135. {
  136. $this->methods = (array) $methods;
  137. }
  138. public function getMethods()
  139. {
  140. return $this->methods;
  141. }
  142. public function setCondition(?string $condition)
  143. {
  144. $this->condition = $condition;
  145. }
  146. public function getCondition()
  147. {
  148. return $this->condition;
  149. }
  150. public function setPriority(int $priority): void
  151. {
  152. $this->priority = $priority;
  153. }
  154. public function getPriority(): ?int
  155. {
  156. return $this->priority;
  157. }
  158. public function setEnv(?string $env): void
  159. {
  160. $this->env = $env;
  161. }
  162. public function getEnv(): ?string
  163. {
  164. return $this->env;
  165. }
  166. }