vendor/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  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 Twig\RuntimeLoader;
  11. use Psr\Container\ContainerInterface;
  12. /**
  13. * Lazily loads Twig runtime implementations from a PSR-11 container.
  14. *
  15. * Note that the runtime services MUST use their class names as identifiers.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. * @author Robin Chalas <robin.chalas@gmail.com>
  19. */
  20. class ContainerRuntimeLoader implements RuntimeLoaderInterface
  21. {
  22. public function __construct(
  23. private ContainerInterface $container,
  24. ) {
  25. }
  26. public function load(string $class)
  27. {
  28. return $this->container->has($class) ? $this->container->get($class) : null;
  29. }
  30. }