ImportConfigurator.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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;
  11. use Symfony\Component\Routing\RouteCollection;
  12. /**
  13. * @author Nicolas Grekas <p@tchwork.com>
  14. */
  15. class ImportConfigurator
  16. {
  17. use Traits\HostTrait;
  18. use Traits\PrefixTrait;
  19. use Traits\RouteTrait;
  20. private $parent;
  21. public function __construct(RouteCollection $parent, RouteCollection $route)
  22. {
  23. $this->parent = $parent;
  24. $this->route = $route;
  25. }
  26. public function __destruct()
  27. {
  28. $this->parent->addCollection($this->route);
  29. }
  30. /**
  31. * Sets the prefix to add to the path of all child routes.
  32. *
  33. * @param string|array $prefix the prefix, or the localized prefixes
  34. *
  35. * @return $this
  36. */
  37. final public function prefix($prefix, bool $trailingSlashOnRoot = true): self
  38. {
  39. $this->addPrefix($this->route, $prefix, $trailingSlashOnRoot);
  40. return $this;
  41. }
  42. /**
  43. * Sets the prefix to add to the name of all child routes.
  44. *
  45. * @return $this
  46. */
  47. final public function namePrefix(string $namePrefix): self
  48. {
  49. $this->route->addNamePrefix($namePrefix);
  50. return $this;
  51. }
  52. /**
  53. * Sets the host to use for all child routes.
  54. *
  55. * @param string|array $host the host, or the localized hosts
  56. *
  57. * @return $this
  58. */
  59. final public function host($host): self
  60. {
  61. $this->addHost($this->route, $host);
  62. return $this;
  63. }
  64. }