From 7dc473cd5892d3b0657dc2c13f7fa60c6d635427 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Thu, 22 Dec 2016 11:22:09 +0100 Subject: [PATCH] Add a runtime loader to the twig bridge to ease upgrading to 3.2 --- src/Symfony/Bridge/Twig/TwigRuntimeLoader.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Symfony/Bridge/Twig/TwigRuntimeLoader.php diff --git a/src/Symfony/Bridge/Twig/TwigRuntimeLoader.php b/src/Symfony/Bridge/Twig/TwigRuntimeLoader.php new file mode 100644 index 0000000000000..df2cd6142e79e --- /dev/null +++ b/src/Symfony/Bridge/Twig/TwigRuntimeLoader.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Twig; + +/** + * Loads Twig extension runtimes. + * + * @author Robin Chalas + */ +class TwigRuntimeLoader implements \Twig_RuntimeLoaderInterface +{ + private $mapping; + + public function __construct(array $mapping) + { + $this->mapping = $mapping; + } + + /** + * {@inheritdoc} + */ + public function load($class) + { + if (isset($this->mapping[$class])) { + return $this->mapping[$class]; + } + + throw new \InvalidArgumentException(sprintf('Class "%s" is not mapped as a Twig runtime.', $class)); + } +}