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\Extension {
13use Twig\TwigFunction;
14
15/**
16 * @final
17 */
18class StringLoaderExtension extends AbstractExtension
19{
20    public function getFunctions()
21    {
22        return [
23            new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
24        ];
25    }
26
27    public function getName()
28    {
29        return 'string_loader';
30    }
31}
32
33class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader');
34}
35
36namespace {
37use Twig\Environment;
38use Twig\Template;
39
40/**
41 * Loads a template from a string.
42 *
43 *     {{ include(template_from_string("Hello {{ name }}")) }}
44 *
45 * @param string $template A template as a string or object implementing __toString()
46 *
47 * @return Template
48 */
49function twig_template_from_string(Environment $env, $template)
50{
51    return $env->createTemplate((string) $template);
52}
53}
54