You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
993 B

3 years ago
  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, string $env = null)
  21. {
  22. $this->container = $container;
  23. parent::__construct($env);
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function supports($resource, string $type = null)
  29. {
  30. return 'service' === $type;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function getObject(string $id)
  36. {
  37. return $this->container->get($id);
  38. }
  39. }