No Description

ContainerLoader.php 956B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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;
  11. use Psr\Container\ContainerInterface;
  12. /**
  13. * A route loader that executes a service from a PSR-11 container to load the routes.
  14. *
  15. * @author Ryan Weaver <ryan@knpuniversity.com>
  16. */
  17. class ContainerLoader extends ObjectLoader
  18. {
  19. private $container;
  20. public function __construct(ContainerInterface $container)
  21. {
  22. $this->container = $container;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function supports($resource, $type = null)
  28. {
  29. return 'service' === $type && \is_string($resource);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function getObject(string $id)
  35. {
  36. return $this->container->get($id);
  37. }
  38. }