ImportConfigurator.php 1.9 KB

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