Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

SearchAndRenderBlockNode.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 4.39 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Bridge\Twig\Node;
013   
014  /**
015   * @author Bernhard Schussek <bschussek@gmail.com>
016   */
017  class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
018  {
019      public function compile(\Twig_Compiler $compiler)
020      {
021          $compiler->addDebugInfo($this);
022          $compiler->raw('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(');
023   
024          preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);
025   
026          $label = null;
027          $arguments = iterator_to_array($this->getNode('arguments'));
028          $blockNameSuffix = $matches[1];
029   
030          if (isset($arguments[0])) {
031              $compiler->subcompile($arguments[0]);
032              $compiler->raw(', \''.$blockNameSuffix.'\'');
033   
034              if (isset($arguments[1])) {
035                  if ('label' === $blockNameSuffix) {
036                      // The "label" function expects the label in the second and
037                      // the variables in the third argument
038                      $label = $arguments[1];
039                      $variables = isset($arguments[2]) ? $arguments[2] : null;
040                      $lineno = $label->getLine();
041   
042                      if ($label instanceof \Twig_Node_Expression_Constant) {
043                          // If the label argument is given as a constant, we can either
044                          // strip it away if it is empty, or integrate it into the array
045                          // of variables at compile time.
046                          $labelIsExpression = false;
047   
048                          // Only insert the label into the array if it is not empty
049                          if (!twig_test_empty($label->getAttribute('value'))) {
050                              $originalVariables = $variables;
051                              $variables = new \Twig_Node_Expression_Array(array(), $lineno);
052                              $labelKey = new \Twig_Node_Expression_Constant('label', $lineno);
053   
054                              if (null !== $originalVariables) {
055                                  foreach ($originalVariables->getKeyValuePairs() as $pair) {
056                                      // Don't copy the original label attribute over if it exists
057                                      if ((string) $labelKey !== (string) $pair['key']) {
058                                          $variables->addElement($pair['value'], $pair['key']);
059                                      }
060                                  }
061                              }
062   
063                              // Insert the label argument into the array
064                              $variables->addElement($label, $labelKey);
065                          }
066                      } else {
067                          // The label argument is not a constant, but some kind of
068                          // expression. This expression needs to be evaluated at runtime.
069                          // Depending on the result (whether it is null or not), the
070                          // label in the arguments should take precedence over the label
071                          // in the attributes or not.
072                          $labelIsExpression = true;
073                      }
074                  } else {
075                      // All other functions than "label" expect the variables
076                      // in the second argument
077                      $label = null;
078                      $variables = $arguments[1];
079                      $labelIsExpression = false;
080                  }
081   
082                  if (null !== $variables || $labelIsExpression) {
083                      $compiler->raw(', ');
084   
085                      if (null !== $variables) {
086                          $compiler->subcompile($variables);
087                      }
088   
089                      if ($labelIsExpression) {
090                          if (null !== $variables) {
091                              $compiler->raw(' + ');
092                          }
093   
094                          // Check at runtime whether the label is empty.
095                          // If not, add it to the array at runtime.
096                          $compiler->raw('(twig_test_empty($_label_ = ');
097                          $compiler->subcompile($label);
098                          $compiler->raw(') ? array() : array("label" => $_label_))');
099                      }
100                  }
101              }
102          }
103   
104          $compiler->raw(')');
105      }
106  }
107