RouteTrait.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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)
  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)
  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)
  45. {
  46. $this->route->addOptions($options);
  47. return $this;
  48. }
  49. /**
  50. * Sets the condition.
  51. *
  52. * @param string $condition
  53. *
  54. * @return $this
  55. */
  56. final public function condition($condition)
  57. {
  58. $this->route->setCondition($condition);
  59. return $this;
  60. }
  61. /**
  62. * Sets the pattern for the host.
  63. *
  64. * @param string $pattern
  65. *
  66. * @return $this
  67. */
  68. final public function host($pattern)
  69. {
  70. $this->route->setHost($pattern);
  71. return $this;
  72. }
  73. /**
  74. * Sets the schemes (e.g. 'https') this route is restricted to.
  75. * So an empty array means that any scheme is allowed.
  76. *
  77. * @param string[] $schemes
  78. *
  79. * @return $this
  80. */
  81. final public function schemes(array $schemes)
  82. {
  83. $this->route->setSchemes($schemes);
  84. return $this;
  85. }
  86. /**
  87. * Sets the HTTP methods (e.g. 'POST') this route is restricted to.
  88. * So an empty array means that any method is allowed.
  89. *
  90. * @param string[] $methods
  91. *
  92. * @return $this
  93. */
  94. final public function methods(array $methods)
  95. {
  96. $this->route->setMethods($methods);
  97. return $this;
  98. }
  99. /**
  100. * Adds the "_controller" entry to defaults.
  101. *
  102. * @param callable|string $controller a callable or parseable pseudo-callable
  103. *
  104. * @return $this
  105. */
  106. final public function controller($controller)
  107. {
  108. $this->route->addDefaults(array('_controller' => $controller));
  109. return $this;
  110. }
  111. }