AddTrait.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Loader\Configurator\RouteConfigurator;
  12. use Symfony\Component\Routing\Route;
  13. use Symfony\Component\Routing\RouteCollection;
  14. trait AddTrait
  15. {
  16. /**
  17. * @var RouteCollection
  18. */
  19. private $collection;
  20. private $name = '';
  21. /**
  22. * Adds a route.
  23. *
  24. * @param string $name
  25. * @param string $path
  26. *
  27. * @return RouteConfigurator
  28. */
  29. final public function add($name, $path)
  30. {
  31. $parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null;
  32. $this->collection->add($this->name.$name, $route = new Route($path));
  33. return new RouteConfigurator($this->collection, $route, '', $parentConfigurator);
  34. }
  35. /**
  36. * Adds a route.
  37. *
  38. * @param string $name
  39. * @param string $path
  40. *
  41. * @return RouteConfigurator
  42. */
  43. final public function __invoke($name, $path)
  44. {
  45. return $this->add($name, $path);
  46. }
  47. }