No Description

RouteTrait.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\Loader\Configurator\Traits;
  11. use Symfony\Component\Routing\Route;
  12. use Symfony\Component\Routing\RouteCollection;
  13. trait RouteTrait
  14. {
  15. /**
  16. * @var RouteCollection|Route
  17. */
  18. private $route;
  19. /**
  20. * Adds defaults.
  21. *
  22. * @return $this
  23. */
  24. final public function defaults(array $defaults): self
  25. {
  26. $this->route->addDefaults($defaults);
  27. return $this;
  28. }
  29. /**
  30. * Adds requirements.
  31. *
  32. * @return $this
  33. */
  34. final public function requirements(array $requirements): self
  35. {
  36. $this->route->addRequirements($requirements);
  37. return $this;
  38. }
  39. /**
  40. * Adds options.
  41. *
  42. * @return $this
  43. */
  44. final public function options(array $options): self
  45. {
  46. $this->route->addOptions($options);
  47. return $this;
  48. }
  49. /**
  50. * Whether paths should accept utf8 encoding.
  51. *
  52. * @return $this
  53. */
  54. final public function utf8(bool $utf8 = true): self
  55. {
  56. $this->route->addOptions(['utf8' => $utf8]);
  57. return $this;
  58. }
  59. /**
  60. * Sets the condition.
  61. *
  62. * @return $this
  63. */
  64. final public function condition(string $condition): self
  65. {
  66. $this->route->setCondition($condition);
  67. return $this;
  68. }
  69. /**
  70. * Sets the pattern for the host.
  71. *
  72. * @return $this
  73. */
  74. final public function host(string $pattern): self
  75. {
  76. $this->route->setHost($pattern);
  77. return $this;
  78. }
  79. /**
  80. * Sets the schemes (e.g. 'https') this route is restricted to.
  81. * So an empty array means that any scheme is allowed.
  82. *
  83. * @param string[] $schemes
  84. *
  85. * @return $this
  86. */
  87. final public function schemes(array $schemes): self
  88. {
  89. $this->route->setSchemes($schemes);
  90. return $this;
  91. }
  92. /**
  93. * Sets the HTTP methods (e.g. 'POST') this route is restricted to.
  94. * So an empty array means that any method is allowed.
  95. *
  96. * @param string[] $methods
  97. *
  98. * @return $this
  99. */
  100. final public function methods(array $methods): self
  101. {
  102. $this->route->setMethods($methods);
  103. return $this;
  104. }
  105. /**
  106. * Adds the "_controller" entry to defaults.
  107. *
  108. * @param callable|string|array $controller a callable or parseable pseudo-callable
  109. *
  110. * @return $this
  111. */
  112. final public function controller($controller): self
  113. {
  114. $this->route->addDefaults(['_controller' => $controller]);
  115. return $this;
  116. }
  117. /**
  118. * Adds the "_locale" entry to defaults.
  119. *
  120. * @return $this
  121. */
  122. final public function locale(string $locale): self
  123. {
  124. $this->route->addDefaults(['_locale' => $locale]);
  125. return $this;
  126. }
  127. /**
  128. * Adds the "_format" entry to defaults.
  129. *
  130. * @return $this
  131. */
  132. final public function format(string $format): self
  133. {
  134. $this->route->addDefaults(['_format' => $format]);
  135. return $this;
  136. }
  137. }