Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

Call.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 6.28 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of Twig.
 005   *
 006   * (c) 2012 Fabien Potencier
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011  abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
 012  {
 013      protected function compileCallable(Twig_Compiler $compiler)
 014      {
 015          $callable = $this->getAttribute('callable');
 016   
 017          $closingParenthesis = false;
 018          if ($callable) {
 019              if (is_string($callable)) {
 020                  $compiler->raw($callable);
 021              } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) {
 022                  $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1]));
 023              } else {
 024                  $type = ucfirst($this->getAttribute('type'));
 025                  $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
 026                  $closingParenthesis = true;
 027              }
 028          } else {
 029              $compiler->raw($this->getAttribute('thing')->compile());
 030          }
 031   
 032          $this->compileArguments($compiler);
 033   
 034          if ($closingParenthesis) {
 035              $compiler->raw(')');
 036          }
 037      }
 038   
 039      protected function compileArguments(Twig_Compiler $compiler)
 040      {
 041          $compiler->raw('(');
 042   
 043          $first = true;
 044   
 045          if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
 046              $compiler->raw('$this->env');
 047              $first = false;
 048          }
 049   
 050          if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
 051              if (!$first) {
 052                  $compiler->raw(', ');
 053              }
 054              $compiler->raw('$context');
 055              $first = false;
 056          }
 057   
 058          if ($this->hasAttribute('arguments')) {
 059              foreach ($this->getAttribute('arguments') as $argument) {
 060                  if (!$first) {
 061                      $compiler->raw(', ');
 062                  }
 063                  $compiler->string($argument);
 064                  $first = false;
 065              }
 066          }
 067   
 068          if ($this->hasNode('node')) {
 069              if (!$first) {
 070                  $compiler->raw(', ');
 071              }
 072              $compiler->subcompile($this->getNode('node'));
 073              $first = false;
 074          }
 075   
 076          if ($this->hasNode('arguments') && null !== $this->getNode('arguments')) {
 077              $callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null;
 078   
 079              $arguments = $this->getArguments($callable, $this->getNode('arguments'));
 080   
 081              foreach ($arguments as $node) {
 082                  if (!$first) {
 083                      $compiler->raw(', ');
 084                  }
 085                  $compiler->subcompile($node);
 086                  $first = false;
 087              }
 088          }
 089   
 090          $compiler->raw(')');
 091      }
 092   
 093      protected function getArguments($callable, $arguments)
 094      {
 095          $parameters = array();
 096          $named = false;
 097          foreach ($arguments as $name => $node) {
 098              if (!is_int($name)) {
 099                  $named = true;
 100                  $name = $this->normalizeName($name);
 101              } elseif ($named) {
 102                  throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $this->getAttribute('type'), $this->getAttribute('name')));
 103              }
 104   
 105              $parameters[$name] = $node;
 106          }
 107   
 108          if (!$named) {
 109              return $parameters;
 110          }
 111   
 112          if (!$callable) {
 113              throw new LogicException(sprintf('Named arguments are not supported for %s "%s".', $this->getAttribute('type'), $this->getAttribute('name')));
 114          }
 115   
 116          // manage named arguments
 117          if (is_array($callable)) {
 118              $r = new ReflectionMethod($callable[0], $callable[1]);
 119          } elseif (is_object($callable) && !$callable instanceof Closure) {
 120              $r = new ReflectionObject($callable);
 121              $r = $r->getMethod('__invoke');
 122          } else {
 123              $r = new ReflectionFunction($callable);
 124          }
 125   
 126          $definition = $r->getParameters();
 127          if ($this->hasNode('node')) {
 128              array_shift($definition);
 129          }
 130          if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
 131              array_shift($definition);
 132          }
 133          if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
 134              array_shift($definition);
 135          }
 136          if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
 137              foreach ($this->getAttribute('arguments') as $argument) {
 138                  array_shift($definition);
 139              }
 140          }
 141   
 142          $arguments = array();
 143          $pos = 0;
 144          foreach ($definition as $param) {
 145              $name = $this->normalizeName($param->name);
 146   
 147              if (array_key_exists($name, $parameters)) {
 148                  if (array_key_exists($pos, $parameters)) {
 149                      throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
 150                  }
 151   
 152                  $arguments[] = $parameters[$name];
 153                  unset($parameters[$name]);
 154              } elseif (array_key_exists($pos, $parameters)) {
 155                  $arguments[] = $parameters[$pos];
 156                  unset($parameters[$pos]);
 157                  ++$pos;
 158              } elseif ($param->isDefaultValueAvailable()) {
 159                  $arguments[] = new Twig_Node_Expression_Constant($param->getDefaultValue(), -1);
 160              } elseif ($param->isOptional()) {
 161                  break;
 162              } else {
 163                  throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
 164              }
 165          }
 166   
 167          if (!empty($parameters)) {
 168              throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '' , implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name')));
 169          }
 170   
 171          return $arguments;
 172      }
 173   
 174      protected function normalizeName($name)
 175      {
 176          return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), $name));
 177      }
 178  }
 179