1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Twig\RuntimeLoader;
13
14/**
15 * Lazy loads the runtime implementations for a Twig element.
16 *
17 * @author Robin Chalas <robin.chalas@gmail.com>
18 */
19class FactoryRuntimeLoader implements RuntimeLoaderInterface
20{
21    private $map;
22
23    /**
24     * @param array $map An array where keys are class names and values factory callables
25     */
26    public function __construct(array $map = [])
27    {
28        $this->map = $map;
29    }
30
31    public function load($class)
32    {
33        if (isset($this->map[$class])) {
34            $runtimeFactory = $this->map[$class];
35
36            return $runtimeFactory();
37        }
38    }
39}
40
41class_alias('Twig\RuntimeLoader\FactoryRuntimeLoader', 'Twig_FactoryRuntimeLoader');
42