blob: 1306483926743dc957add263e39feee99c21ca7a [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?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(string $class)
32 {
33 if (!isset($this->map[$class])) {
34 return null;
35 }
36
37 $runtimeFactory = $this->map[$class];
38
39 return $runtimeFactory();
40 }
41}