Route.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @author Fabien Potencier <fabien@symfony.com>
  13. * @author Alexander M. Turek <me@derrabus.de>
  14. */
  15. #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
  16. class Route
  17. {
  18. /** @var string[] */
  19. public array $methods;
  20. /** @var string[] */
  21. public array $envs;
  22. /** @var string[] */
  23. public array $schemes;
  24. /** @var (string|DeprecatedAlias)[] */
  25. public array $aliases = [];
  26. /**
  27. * @param string|array<string,string>|null $path The route path (i.e. "/user/login")
  28. * @param string|null $name The route name (i.e. "app_user_login")
  29. * @param array<string|\Stringable> $requirements Requirements for the route attributes, @see https://symfony.com/doc/current/routing.html#parameters-validation
  30. * @param array<string, mixed> $options Options for the route (i.e. ['prefix' => '/api'])
  31. * @param array<string, mixed> $defaults Default values for the route attributes and query parameters
  32. * @param string|null $host The host for which this route should be active (i.e. "localhost")
  33. * @param string|string[] $methods The list of HTTP methods allowed by this route
  34. * @param string|string[] $schemes The list of schemes allowed by this route (i.e. "https")
  35. * @param string|null $condition An expression that must evaluate to true for the route to be matched, @see https://symfony.com/doc/current/routing.html#matching-expressions
  36. * @param int|null $priority The priority of the route if multiple ones are defined for the same path
  37. * @param string|null $locale The locale accepted by the route
  38. * @param string|null $format The format returned by the route (i.e. "json", "xml")
  39. * @param bool|null $utf8 Whether the route accepts UTF-8 in its parameters
  40. * @param bool|null $stateless Whether the route is defined as stateless or stateful, @see https://symfony.com/doc/current/routing.html#stateless-routes
  41. * @param string|string[]|null $env The env(s) in which the route is defined (i.e. "dev", "test", "prod", ["dev", "test"])
  42. * @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $alias The list of aliases for this route
  43. */
  44. public function __construct(
  45. public string|array|null $path = null,
  46. public ?string $name = null,
  47. public array $requirements = [],
  48. public array $options = [],
  49. public array $defaults = [],
  50. public ?string $host = null,
  51. array|string $methods = [],
  52. array|string $schemes = [],
  53. public ?string $condition = null,
  54. public ?int $priority = null,
  55. ?string $locale = null,
  56. ?string $format = null,
  57. ?bool $utf8 = null,
  58. ?bool $stateless = null,
  59. string|array|null $env = null,
  60. string|DeprecatedAlias|array $alias = [],
  61. ) {
  62. $this->path = $path;
  63. $this->methods = (array) $methods;
  64. $this->schemes = (array) $schemes;
  65. $this->envs = (array) $env;
  66. $this->aliases = \is_array($alias) ? $alias : [$alias];
  67. if (null !== $locale) {
  68. $this->defaults['_locale'] = $locale;
  69. }
  70. if (null !== $format) {
  71. $this->defaults['_format'] = $format;
  72. }
  73. if (null !== $utf8) {
  74. $this->options['utf8'] = $utf8;
  75. }
  76. if (null !== $stateless) {
  77. $this->defaults['_stateless'] = $stateless;
  78. }
  79. }
  80. }