ImportConfigurator.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 __sleep()
  27. {
  28. throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
  29. }
  30. public function __wakeup()
  31. {
  32. throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
  33. }
  34. public function __destruct()
  35. {
  36. $this->parent->addCollection($this->route);
  37. }
  38. /**
  39. * Sets the prefix to add to the path of all child routes.
  40. *
  41. * @param string|array $prefix the prefix, or the localized prefixes
  42. *
  43. * @return $this
  44. */
  45. final public function prefix($prefix, bool $trailingSlashOnRoot = true): self
  46. {
  47. $this->addPrefix($this->route, $prefix, $trailingSlashOnRoot);
  48. return $this;
  49. }
  50. /**
  51. * Sets the prefix to add to the name of all child routes.
  52. *
  53. * @return $this
  54. */
  55. final public function namePrefix(string $namePrefix): self
  56. {
  57. $this->route->addNamePrefix($namePrefix);
  58. return $this;
  59. }
  60. /**
  61. * Sets the host to use for all child routes.
  62. *
  63. * @param string|array $host the host, or the localized hosts
  64. *
  65. * @return $this
  66. */
  67. final public function host($host): self
  68. {
  69. $this->addHost($this->route, $host);
  70. return $this;
  71. }
  72. }