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)); + } +}