ContainerLoader.php 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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, string $type = null)
  28. {
  29. return 'service' === $type;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function getObject(string $id)
  35. {
  36. return $this->container->get($id);
  37. }
  38. }