Security update to Drupal 8.4.6
[yaffs-website] / vendor / twig / twig / lib / Twig / TemplateWrapper.php
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
12 /**
13  * Exposes a template to userland.
14  *
15  * @author Fabien Potencier <fabien@symfony.com>
16  */
17 final class Twig_TemplateWrapper
18 {
19     private $env;
20     private $template;
21
22     /**
23      * This method is for internal use only and should never be called
24      * directly (use Twig_Environment::load() instead).
25      *
26      * @internal
27      */
28     public function __construct(Twig_Environment $env, Twig_Template $template)
29     {
30         $this->env = $env;
31         $this->template = $template;
32     }
33
34     /**
35      * Renders the template.
36      *
37      * @param array $context An array of parameters to pass to the template
38      *
39      * @return string The rendered template
40      */
41     public function render($context = array())
42     {
43         return $this->template->render($context);
44     }
45
46     /**
47      * Displays the template.
48      *
49      * @param array $context An array of parameters to pass to the template
50      */
51     public function display($context = array())
52     {
53         $this->template->display($context);
54     }
55
56     /**
57      * Checks if a block is defined.
58      *
59      * @param string $name    The block name
60      * @param array  $context An array of parameters to pass to the template
61      *
62      * @return bool
63      */
64     public function hasBlock($name, $context = array())
65     {
66         return $this->template->hasBlock($name, $context);
67     }
68
69     /**
70      * Returns defined block names in the template.
71      *
72      * @param array $context An array of parameters to pass to the template
73      *
74      * @return string[] An array of defined template block names
75      */
76     public function getBlockNames($context = array())
77     {
78         return $this->template->getBlockNames($context);
79     }
80
81     /**
82      * Renders a template block.
83      *
84      * @param string $name    The block name to render
85      * @param array  $context An array of parameters to pass to the template
86      *
87      * @return string The rendered block
88      */
89     public function renderBlock($name, $context = array())
90     {
91         $context = $this->env->mergeGlobals($context);
92         $level = ob_get_level();
93         ob_start();
94         try {
95             $this->template->displayBlock($name, $context);
96         } catch (Exception $e) {
97             while (ob_get_level() > $level) {
98                 ob_end_clean();
99             }
100
101             throw $e;
102         } catch (Throwable $e) {
103             while (ob_get_level() > $level) {
104                 ob_end_clean();
105             }
106
107             throw $e;
108         }
109
110         return ob_get_clean();
111     }
112
113     /**
114      * Displays a template block.
115      *
116      * @param string $name    The block name to render
117      * @param array  $context An array of parameters to pass to the template
118      */
119     public function displayBlock($name, $context = array())
120     {
121         $this->template->displayBlock($name, $this->env->mergeGlobals($context));
122     }
123
124     /**
125      * @return Twig_Source
126      */
127     public function getSourceContext()
128     {
129         return $this->template->getSourceContext();
130     }
131 }
132
133 class_alias('Twig_TemplateWrapper', 'Twig\TemplateWrapper', false);