vendor/twig/twig/src/Template.php line 381

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  * (c) Armin Ronacher
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Twig;
  12. use Twig\Error\Error;
  13. use Twig\Error\LoaderError;
  14. use Twig\Error\RuntimeError;
  15. /**
  16.  * Default base class for compiled templates.
  17.  *
  18.  * This class is an implementation detail of how template compilation currently
  19.  * works, which might change. It should never be used directly. Use $twig->load()
  20.  * instead, which returns an instance of \Twig\TemplateWrapper.
  21.  *
  22.  * @author Fabien Potencier <fabien@symfony.com>
  23.  *
  24.  * @internal
  25.  */
  26. abstract class Template
  27. {
  28.     public const ANY_CALL 'any';
  29.     public const ARRAY_CALL 'array';
  30.     public const METHOD_CALL 'method';
  31.     protected $parent;
  32.     protected $parents = [];
  33.     protected $env;
  34.     protected $blocks = [];
  35.     protected $traits = [];
  36.     protected $extensions = [];
  37.     protected $sandbox;
  38.     public function __construct(Environment $env)
  39.     {
  40.         $this->env $env;
  41.         $this->extensions $env->getExtensions();
  42.     }
  43.     /**
  44.      * @internal this method will be removed in 3.0 and is only used internally to provide an upgrade path from 1.x to 2.0
  45.      */
  46.     public function __toString()
  47.     {
  48.         return $this->getTemplateName();
  49.     }
  50.     /**
  51.      * Returns the template name.
  52.      *
  53.      * @return string The template name
  54.      */
  55.     abstract public function getTemplateName();
  56.     /**
  57.      * Returns debug information about the template.
  58.      *
  59.      * @return array Debug information
  60.      */
  61.     abstract public function getDebugInfo();
  62.     /**
  63.      * Returns information about the original template source code.
  64.      *
  65.      * @return Source
  66.      */
  67.     public function getSourceContext()
  68.     {
  69.         return new Source(''$this->getTemplateName());
  70.     }
  71.     /**
  72.      * Returns the parent template.
  73.      *
  74.      * This method is for internal use only and should never be called
  75.      * directly.
  76.      *
  77.      * @return Template|TemplateWrapper|false The parent template or false if there is no parent
  78.      */
  79.     public function getParent(array $context)
  80.     {
  81.         if (null !== $this->parent) {
  82.             return $this->parent;
  83.         }
  84.         try {
  85.             $parent $this->doGetParent($context);
  86.             if (false === $parent) {
  87.                 return false;
  88.             }
  89.             if ($parent instanceof self || $parent instanceof TemplateWrapper) {
  90.                 return $this->parents[$parent->getSourceContext()->getName()] = $parent;
  91.             }
  92.             if (!isset($this->parents[$parent])) {
  93.                 $this->parents[$parent] = $this->loadTemplate($parent);
  94.             }
  95.         } catch (LoaderError $e) {
  96.             $e->setSourceContext(null);
  97.             $e->guess();
  98.             throw $e;
  99.         }
  100.         return $this->parents[$parent];
  101.     }
  102.     protected function doGetParent(array $context)
  103.     {
  104.         return false;
  105.     }
  106.     public function isTraitable()
  107.     {
  108.         return true;
  109.     }
  110.     /**
  111.      * Displays a parent block.
  112.      *
  113.      * This method is for internal use only and should never be called
  114.      * directly.
  115.      *
  116.      * @param string $name    The block name to display from the parent
  117.      * @param array  $context The context
  118.      * @param array  $blocks  The current set of blocks
  119.      */
  120.     public function displayParentBlock($name, array $context, array $blocks = [])
  121.     {
  122.         if (isset($this->traits[$name])) {
  123.             $this->traits[$name][0]->displayBlock($name$context$blocksfalse);
  124.         } elseif (false !== $parent $this->getParent($context)) {
  125.             $parent->displayBlock($name$context$blocksfalse);
  126.         } else {
  127.             throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.'$name), -1$this->getSourceContext());
  128.         }
  129.     }
  130.     /**
  131.      * Displays a block.
  132.      *
  133.      * This method is for internal use only and should never be called
  134.      * directly.
  135.      *
  136.      * @param string $name      The block name to display
  137.      * @param array  $context   The context
  138.      * @param array  $blocks    The current set of blocks
  139.      * @param bool   $useBlocks Whether to use the current set of blocks
  140.      */
  141.     public function displayBlock($name, array $context, array $blocks = [], $useBlocks trueself $templateContext null)
  142.     {
  143.         if ($useBlocks && isset($blocks[$name])) {
  144.             $template $blocks[$name][0];
  145.             $block $blocks[$name][1];
  146.         } elseif (isset($this->blocks[$name])) {
  147.             $template $this->blocks[$name][0];
  148.             $block $this->blocks[$name][1];
  149.         } else {
  150.             $template null;
  151.             $block null;
  152.         }
  153.         // avoid RCEs when sandbox is enabled
  154.         if (null !== $template && !$template instanceof self) {
  155.             throw new \LogicException('A block must be a method on a \Twig\Template instance.');
  156.         }
  157.         if (null !== $template) {
  158.             try {
  159.                 $template->$block($context$blocks);
  160.             } catch (Error $e) {
  161.                 if (!$e->getSourceContext()) {
  162.                     $e->setSourceContext($template->getSourceContext());
  163.                 }
  164.                 // this is mostly useful for \Twig\Error\LoaderError exceptions
  165.                 // see \Twig\Error\LoaderError
  166.                 if (-=== $e->getTemplateLine()) {
  167.                     $e->guess();
  168.                 }
  169.                 throw $e;
  170.             } catch (\Exception $e) {
  171.                 $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").'$e->getMessage()), -1$template->getSourceContext(), $e);
  172.                 $e->guess();
  173.                 throw $e;
  174.             }
  175.         } elseif (false !== $parent $this->getParent($context)) {
  176.             $parent->displayBlock($name$contextarray_merge($this->blocks$blocks), false$templateContext ?? $this);
  177.         } elseif (isset($blocks[$name])) {
  178.             throw new RuntimeError(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".'$name$blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1$blocks[$name][0]->getSourceContext());
  179.         } else {
  180.             throw new RuntimeError(sprintf('Block "%s" on template "%s" does not exist.'$name$this->getTemplateName()), -1, ($templateContext ?? $this)->getSourceContext());
  181.         }
  182.     }
  183.     /**
  184.      * Renders a parent block.
  185.      *
  186.      * This method is for internal use only and should never be called
  187.      * directly.
  188.      *
  189.      * @param string $name    The block name to render from the parent
  190.      * @param array  $context The context
  191.      * @param array  $blocks  The current set of blocks
  192.      *
  193.      * @return string The rendered block
  194.      */
  195.     public function renderParentBlock($name, array $context, array $blocks = [])
  196.     {
  197.         if ($this->env->isDebug()) {
  198.             ob_start();
  199.         } else {
  200.             ob_start(function () { return ''; });
  201.         }
  202.         $this->displayParentBlock($name$context$blocks);
  203.         return ob_get_clean();
  204.     }
  205.     /**
  206.      * Renders a block.
  207.      *
  208.      * This method is for internal use only and should never be called
  209.      * directly.
  210.      *
  211.      * @param string $name      The block name to render
  212.      * @param array  $context   The context
  213.      * @param array  $blocks    The current set of blocks
  214.      * @param bool   $useBlocks Whether to use the current set of blocks
  215.      *
  216.      * @return string The rendered block
  217.      */
  218.     public function renderBlock($name, array $context, array $blocks = [], $useBlocks true)
  219.     {
  220.         if ($this->env->isDebug()) {
  221.             ob_start();
  222.         } else {
  223.             ob_start(function () { return ''; });
  224.         }
  225.         $this->displayBlock($name$context$blocks$useBlocks);
  226.         return ob_get_clean();
  227.     }
  228.     /**
  229.      * Returns whether a block exists or not in the current context of the template.
  230.      *
  231.      * This method checks blocks defined in the current template
  232.      * or defined in "used" traits or defined in parent templates.
  233.      *
  234.      * @param string $name    The block name
  235.      * @param array  $context The context
  236.      * @param array  $blocks  The current set of blocks
  237.      *
  238.      * @return bool true if the block exists, false otherwise
  239.      */
  240.     public function hasBlock($name, array $context, array $blocks = [])
  241.     {
  242.         if (isset($blocks[$name])) {
  243.             return $blocks[$name][0] instanceof self;
  244.         }
  245.         if (isset($this->blocks[$name])) {
  246.             return true;
  247.         }
  248.         if (false !== $parent $this->getParent($context)) {
  249.             return $parent->hasBlock($name$context);
  250.         }
  251.         return false;
  252.     }
  253.     /**
  254.      * Returns all block names in the current context of the template.
  255.      *
  256.      * This method checks blocks defined in the current template
  257.      * or defined in "used" traits or defined in parent templates.
  258.      *
  259.      * @param array $context The context
  260.      * @param array $blocks  The current set of blocks
  261.      *
  262.      * @return array An array of block names
  263.      */
  264.     public function getBlockNames(array $context, array $blocks = [])
  265.     {
  266.         $names array_merge(array_keys($blocks), array_keys($this->blocks));
  267.         if (false !== $parent $this->getParent($context)) {
  268.             $names array_merge($names$parent->getBlockNames($context));
  269.         }
  270.         return array_unique($names);
  271.     }
  272.     /**
  273.      * @return Template|TemplateWrapper
  274.      */
  275.     protected function loadTemplate($template$templateName null$line null$index null)
  276.     {
  277.         try {
  278.             if (\is_array($template)) {
  279.                 return $this->env->resolveTemplate($template);
  280.             }
  281.             if ($template instanceof self || $template instanceof TemplateWrapper) {
  282.                 return $template;
  283.             }
  284.             if ($template === $this->getTemplateName()) {
  285.                 $class = static::class;
  286.                 if (false !== $pos strrpos($class'___', -1)) {
  287.                     $class substr($class0$pos);
  288.                 }
  289.                 return $this->env->loadClass($class$template$index);
  290.             }
  291.             return $this->env->loadTemplate($template$index);
  292.         } catch (Error $e) {
  293.             if (!$e->getSourceContext()) {
  294.                 $e->setSourceContext($templateName ? new Source(''$templateName) : $this->getSourceContext());
  295.             }
  296.             if ($e->getTemplateLine() > 0) {
  297.                 throw $e;
  298.             }
  299.             if (!$line) {
  300.                 $e->guess();
  301.             } else {
  302.                 $e->setTemplateLine($line);
  303.             }
  304.             throw $e;
  305.         }
  306.     }
  307.     /**
  308.      * @internal
  309.      *
  310.      * @return Template
  311.      */
  312.     public function unwrap()
  313.     {
  314.         return $this;
  315.     }
  316.     /**
  317.      * Returns all blocks.
  318.      *
  319.      * This method is for internal use only and should never be called
  320.      * directly.
  321.      *
  322.      * @return array An array of blocks
  323.      */
  324.     public function getBlocks()
  325.     {
  326.         return $this->blocks;
  327.     }
  328.     public function display(array $context, array $blocks = [])
  329.     {
  330.         $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks$blocks));
  331.     }
  332.     public function render(array $context)
  333.     {
  334.         $level ob_get_level();
  335.         if ($this->env->isDebug()) {
  336.             ob_start();
  337.         } else {
  338.             ob_start(function () { return ''; });
  339.         }
  340.         try {
  341.             $this->display($context);
  342.         } catch (\Throwable $e) {
  343.             while (ob_get_level() > $level) {
  344.                 ob_end_clean();
  345.             }
  346.             throw $e;
  347.         }
  348.         return ob_get_clean();
  349.     }
  350.     protected function displayWithErrorHandling(array $context, array $blocks = [])
  351.     {
  352.         try {
  353.             $this->doDisplay($context$blocks);
  354.         } catch (Error $e) {
  355.             if (!$e->getSourceContext()) {
  356.                 $e->setSourceContext($this->getSourceContext());
  357.             }
  358.             // this is mostly useful for \Twig\Error\LoaderError exceptions
  359.             // see \Twig\Error\LoaderError
  360.             if (-=== $e->getTemplateLine()) {
  361.                 $e->guess();
  362.             }
  363.             throw $e;
  364.         } catch (\Exception $e) {
  365.             $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").'$e->getMessage()), -1$this->getSourceContext(), $e);
  366.             $e->guess();
  367.             throw $e;
  368.         }
  369.     }
  370.     /**
  371.      * Auto-generated method to display the template with the given context.
  372.      *
  373.      * @param array $context An array of parameters to pass to the template
  374.      * @param array $blocks  An array of blocks to pass to the template
  375.      */
  376.     abstract protected function doDisplay(array $context, array $blocks = []);
  377. }
  378. class_alias('Twig\Template''Twig_Template');
dobrowin | betleao | moverbet | winzada 777 | supremo | casadeapostas | dobrowin | betleao | moverbet | wazamba | fezbet | betsson | lvbet | dobrowin | betsul | pixbet | bwin | betobet | dobrowin | bet7 | betcris | blaze | 888 | betano | stake | stake | esportesdasorte | betmotion | rivalry | novibet | pinnacle | cbet | dobrowin | betleao | moverbet | gogowin | jogos win | campobet | mesk bet | infinity bet | betfury | doce | bet7k | jogowin | lobo888 | iribet | leao | dobrowin | allwin | aajogo | pgwin | greenbets | brapub | moverbet | onebra | flames | brdice | brwin | poplottery | queens | winbrl | omgbet | winbra | goinbet | codbet | betleao | fuwin | allwin568 | wingdus | juntosbet | today | talon777 | brlwin | fazobetai | pinup bet | bet sport | bet esporte | mrbet | premier bet | apostebet | spicy bet | prosport bet | bet nacional | luck | jogodeouro | heads bet | marjack bet | apostaganha | gbg bet | esoccer bet | esport bet | realbet | aposte e ganhe | aviator aposta | bet vitoria | imperador bet | realsbet | bet favorita | esportenet | flames bet | pague bet | betsury | doce888 | obabet | winzada | globalbet | bet77 | lottoland | 7gamesbet | dicasbet | esportivabet | tvbet | sportbet | misterjackbet | esportebet | nacionalbet | simplesbet | betestrela | batbet | Pk55 | Bet61 | Upsports Bet | roleta online | roleta | poker online | poker | blackjack online | bingo | 12bet | 33win | bet168 | bk8 | bong88 | bong99 | fcb8 | hb88 | hotlive | ibet888 | k8 | kubet77 | kubet | lode88 | mig8 | nbet | onebox63 | oxbet | s666 | sbobet | suncity | vwin | w88 | win2888 | zbet | xoso66 | zowin | sun | top88 | vnloto | 11bet | bet69 | 8xbet | Ceará | Paysandu | Juventude | Bahia | Sport | Cuiabá | Coritiba | Criciúma | Vitória | Fortaleza | Corinthians | São Paulo | Vasco | Grêmio | Fluminense | Cruzeiro | Botafogo | Flamengo | bingo slots | slots slots | hacker do slot | pg slot demo | slot win | pg slot soft | arne slot | riqueza slots | slots 777 | pg slot | 777 slot game | slot pg soft | hacker slot | 777 slots | slot-pg-soft | fortune ox demo grátis | demo fortune ox | fortune mouse demo | fortune ox demo | jogo fortune tiger | fortune tiger grátis | fortune tiger baixar | fortune tiger demo grátis | fortune tiger demo | fortune tiger 777 | 580bet | bet 7k | leao | luck 2 | john bet | 7755 bet | cbet | bet7 | pk55 | 8800 bet | doce | bet 4 | f12bet | bet7 | ggbet | bet77 | mrbet | bet61 | tvbet | pgwin | today | fuwin | brwin | bet7k | tv bet | allwin | stake | bwin 789 | lvbet | blaze | dj bet | umbet | b1bet | 20bet | bk bet | h2bet | 7kbet | fbbet | 9d bet | 9k bet | 73 bet | ktobet | 74 bet | betpix | betvip | batbet | onabet | f12bet | codbet | winbra | b2xbet | obabet | brlwin | onebra | winbrl | omgbet | queens | brdice | brapub | flames | betano | aajogo | iribet | pixbet | betsul | fezbet | curso beta | betway | bkbet | peixe beta | bet365 | pixbet | 4 play bet | 365bet | brxbet | 939 bet | seubet | cnc bet | gbg bet | 522bet | brl bet | pagbet | jonbet | jqk bet | 166bet | abc bet | bggbet | obabet | 136bet | mmabet | win bet | ir6 bet | 667bet | qqq bet | 193 bet | 3ss bet | 317 bet | kkk bet | 585 bet | 569 bet | vai bet | aaa bet | 969 bet | z11 bet | kw bet | 26 bet | mj bet | betio | 01 bet | ut bet | 9y bet | bet70 | f9 bet | hw bet | kg bet | 5e bet | bet br | hr bet | br bet | 75 bet | 03 bet | 6z bet | 6r bet | v6 bet | 78 bet | bt bet | 80 bet | 8g bet | 72 bet | xp bet | f12 bet | p9 bet | 5 bet | 4 bet | bet 4 | r7 bet | um bet | 29 bet | 5s bet | ck bet | pg bet | ea bet | 23 bet | bl bet | 3l bet | 2a bet | p7 bet | 888 bet | 707 bet | 361 bet | bet29 | 700 bet | 161 bet | bet777 | up bet | 58 bet | nn bet | 67 bet | 22 bet | 9g bet | 1x bet | bet10 | 70 bet | 2h bet | 9r bet | 16 bet | 81 bet | 7 bet | 5u bet | 6k bet | mg bet | b1 bet | 5h bet | je- bet | joya | hopa | nomini | ls bet | 1xbit | platin | ice bet | rant | bet us | bet go | 31 bet | slingo | flush | ice36 | weiss | bet9 | rabona | i bet | starda | dreams | bongo | snatch | 10 bet | daddy | metal | zep bet | drip | gama | drake | verde | shazam | wish | thor | exclusive | sol | highway | 500 casino | jazz | howl | supernova | sherbet | fresh | daddy | jet | wish | eclipse | inplay | drip | marvel | stake | scorpion | luxebet | drake | thor | puma | winzir | loki | shazam | rivalry | f1 casino | xgbet | sushi | bk8 | art casino | manga | pgasia | gemini | bingoplus | slot vip | help slot win | 8k8 slot | tadhana slot | jili slot | 55bmw slot | vip slot | nn777 slot | jili slot 777 | tg777 slot | w500 slot | phfun slot | bmw55 slot | sg777 slot | wj slot | slot free 100 | lucky cola slot | cc6 slot | taya777 slot | ph444 slot | slot games | fb777 slot | okebet slot | help slot | tg77 slot | phwin slot | vvjl slot | fc777 slot | slot vin | yy777 slot | define slot | define slot | inplay | 99bet | 60win | melbet | jollibet | jili slot | rich711 | tayabet | phl63 | unobet | 63jili | mwplay888 | gold99 | jolibet | ubet95 | nice88 | jili777 | nn777 | phlove | jiliko | 55bmw | phoenix game | 8k8 | cgebet | 7up gaming | diamond game | hellowin | win88 | big win | kabibe game | sabong bet | phcity | colorplay | tongits go | slotsgo | spinph | go perya | casino frenzy | aurora game | escala gaming | winning plus | bingo plus | ph dream | 747 live | niceph | lucky cola | pera play