[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/Node/ -> DumpNode.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   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 Symfony\Bridge\Twig\Node;
  13  
  14  use Twig\Compiler;
  15  use Twig\Node\Node;
  16  
  17  /**
  18   * @author Julien Galenski <julien.galenski@gmail.com>
  19   */
  20  class DumpNode extends Node
  21  {
  22      private $varPrefix;
  23  
  24      public function __construct($varPrefix, Node $values = null, $lineno, $tag = null)
  25      {
  26          $nodes = [];
  27          if (null !== $values) {
  28              $nodes['values'] = $values;
  29          }
  30  
  31          parent::__construct($nodes, [], $lineno, $tag);
  32          $this->varPrefix = $varPrefix;
  33      }
  34  
  35      /**
  36       * {@inheritdoc}
  37       */
  38      public function compile(Compiler $compiler)
  39      {
  40          $compiler
  41              ->write("if (\$this->env->isDebug()) {\n")
  42              ->indent();
  43  
  44          if (!$this->hasNode('values')) {
  45              // remove embedded templates (macros) from the context
  46              $compiler
  47                  ->write(sprintf('$%svars = [];'."\n", $this->varPrefix))
  48                  ->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
  49                  ->indent()
  50                  ->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
  51                  ->indent()
  52                  ->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
  53                  ->outdent()
  54                  ->write("}\n")
  55                  ->outdent()
  56                  ->write("}\n")
  57                  ->addDebugInfo($this)
  58                  ->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix));
  59          } elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
  60              $compiler
  61                  ->addDebugInfo($this)
  62                  ->write('\Symfony\Component\VarDumper\VarDumper::dump(')
  63                  ->subcompile($values->getNode(0))
  64                  ->raw(");\n");
  65          } else {
  66              $compiler
  67                  ->addDebugInfo($this)
  68                  ->write('\Symfony\Component\VarDumper\VarDumper::dump(['."\n")
  69                  ->indent();
  70              foreach ($values as $node) {
  71                  $compiler->write('');
  72                  if ($node->hasAttribute('name')) {
  73                      $compiler
  74                          ->string($node->getAttribute('name'))
  75                          ->raw(' => ');
  76                  }
  77                  $compiler
  78                      ->subcompile($node)
  79                      ->raw(",\n");
  80              }
  81              $compiler
  82                  ->outdent()
  83                  ->write("]);\n");
  84          }
  85  
  86          $compiler
  87              ->outdent()
  88              ->write("}\n");
  89      }
  90  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1