[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/twig/twig/src/ -> TemplateWrapper.php (source)

   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  namespace Twig;
  13  
  14  /**
  15   * Exposes a template to userland.
  16   *
  17   * @author Fabien Potencier <fabien@symfony.com>
  18   */
  19  final class TemplateWrapper
  20  {
  21      private $env;
  22      private $template;
  23  
  24      /**
  25       * This method is for internal use only and should never be called
  26       * directly (use Twig\Environment::load() instead).
  27       *
  28       * @internal
  29       */
  30      public function __construct(Environment $env, Template $template)
  31      {
  32          $this->env = $env;
  33          $this->template = $template;
  34      }
  35  
  36      /**
  37       * Renders the template.
  38       *
  39       * @param array $context An array of parameters to pass to the template
  40       *
  41       * @return string The rendered template
  42       */
  43      public function render($context = [])
  44      {
  45          // using func_get_args() allows to not expose the blocks argument
  46          // as it should only be used by internal code
  47          return $this->template->render($context, \func_num_args() > 1 ? func_get_arg(1) : []);
  48      }
  49  
  50      /**
  51       * Displays the template.
  52       *
  53       * @param array $context An array of parameters to pass to the template
  54       */
  55      public function display($context = [])
  56      {
  57          // using func_get_args() allows to not expose the blocks argument
  58          // as it should only be used by internal code
  59          $this->template->display($context, \func_num_args() > 1 ? func_get_arg(1) : []);
  60      }
  61  
  62      /**
  63       * Checks if a block is defined.
  64       *
  65       * @param string $name    The block name
  66       * @param array  $context An array of parameters to pass to the template
  67       *
  68       * @return bool
  69       */
  70      public function hasBlock($name, $context = [])
  71      {
  72          return $this->template->hasBlock($name, $context);
  73      }
  74  
  75      /**
  76       * Returns defined block names in the template.
  77       *
  78       * @param array $context An array of parameters to pass to the template
  79       *
  80       * @return string[] An array of defined template block names
  81       */
  82      public function getBlockNames($context = [])
  83      {
  84          return $this->template->getBlockNames($context);
  85      }
  86  
  87      /**
  88       * Renders a template block.
  89       *
  90       * @param string $name    The block name to render
  91       * @param array  $context An array of parameters to pass to the template
  92       *
  93       * @return string The rendered block
  94       */
  95      public function renderBlock($name, $context = [])
  96      {
  97          $context = $this->env->mergeGlobals($context);
  98          $level = ob_get_level();
  99          if ($this->env->isDebug()) {
 100              ob_start();
 101          } else {
 102              ob_start(function () { return ''; });
 103          }
 104          try {
 105              $this->template->displayBlock($name, $context);
 106          } catch (\Exception $e) {
 107              while (ob_get_level() > $level) {
 108                  ob_end_clean();
 109              }
 110  
 111              throw $e;
 112          } catch (\Throwable $e) {
 113              while (ob_get_level() > $level) {
 114                  ob_end_clean();
 115              }
 116  
 117              throw $e;
 118          }
 119  
 120          return ob_get_clean();
 121      }
 122  
 123      /**
 124       * Displays a template block.
 125       *
 126       * @param string $name    The block name to render
 127       * @param array  $context An array of parameters to pass to the template
 128       */
 129      public function displayBlock($name, $context = [])
 130      {
 131          $this->template->displayBlock($name, $this->env->mergeGlobals($context));
 132      }
 133  
 134      /**
 135       * @return Source
 136       */
 137      public function getSourceContext()
 138      {
 139          return $this->template->getSourceContext();
 140      }
 141  
 142      /**
 143       * @return string
 144       */
 145      public function getTemplateName()
 146      {
 147          return $this->template->getTemplateName();
 148      }
 149  
 150      /**
 151       * @internal
 152       *
 153       * @return Template
 154       */
 155      public function unwrap()
 156      {
 157          return $this->template;
 158      }
 159  }
 160  
 161  class_alias('Twig\TemplateWrapper', 'Twig_TemplateWrapper');


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1