vendor/phive/twig-extensions-deferred/src/DeferredExtension.php line 29

Open in your IDE?
  1. <?php
  2. namespace Phive\Twig\Extensions\Deferred;
  3. use Twig\Extension\AbstractExtension;
  4. use Twig\Template;
  5. class DeferredExtension extends AbstractExtension
  6. {
  7.     private $blocks = [];
  8.     public function getTokenParsers()
  9.     {
  10.         return [new DeferredTokenParser()];
  11.     }
  12.     public function getNodeVisitors()
  13.     {
  14.         return [new DeferredNodeVisitor()];
  15.     }
  16.     public function defer(Template $template$blockName)
  17.     {
  18.         $templateName $template->getTemplateName();
  19.         $this->blocks[$templateName][] = $blockName;
  20.         ob_start();
  21.     }
  22.     public function resolve(Template $template, array $context, array $blocks)
  23.     {
  24.         $templateName $template->getTemplateName();
  25.         if (empty($this->blocks[$templateName])) {
  26.             return;
  27.         }
  28.         while ($blockName array_pop($this->blocks[$templateName])) {
  29.             $buffer ob_get_clean();
  30.             $blocks[$blockName] = [$template'block_'.$blockName.'_deferred'];
  31.             $template->displayBlock($blockName$context$blocks);
  32.             echo $buffer;
  33.         }
  34.         if ($parent $template->getParent($context)) {
  35.             $this->resolve($parent$context$blocks);
  36.         }
  37.     }
  38. }