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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Macro.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) 2009 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
012 /**
013 * Represents a macro node.
014 *
015 * @author Fabien Potencier <fabien@symfony.com>
016 */
017 class Twig_Node_Macro extends Twig_Node
018 {
019 const VARARGS_NAME = 'varargs';
020
021 public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null)
022 {
023 foreach ($arguments as $argumentName => $argument) {
024 if (self::VARARGS_NAME === $argumentName) {
025 throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getLine());
026 }
027 }
028
029 parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag);
030 }
031
032 public function compile(Twig_Compiler $compiler)
033 {
034 $compiler
035 ->addDebugInfo($this)
036 ->write(sprintf('public function get%s(', $this->getAttribute('name')))
037 ;
038
039 $count = count($this->getNode('arguments'));
040 $pos = 0;
041 foreach ($this->getNode('arguments') as $name => $default) {
042 $compiler
043 ->raw('$__'.$name.'__ = ')
044 ->subcompile($default)
045 ;
046
047 if (++$pos < $count) {
048 $compiler->raw(', ');
049 }
050 }
051
052 if (PHP_VERSION_ID >= 50600) {
053 if ($count) {
054 $compiler->raw(', ');
055 }
056
057 $compiler->raw('...$__varargs__');
058 }
059
060 $compiler
061 ->raw(")\n")
062 ->write("{\n")
063 ->indent()
064 ;
065
066 $compiler
067 ->write("\$context = \$this->env->mergeGlobals(array(\n")
068 ->indent()
069 ;
070
071 foreach ($this->getNode('arguments') as $name => $default) {
072 $compiler
073 ->addIndentation()
074 ->string($name)
075 ->raw(' => $__'.$name.'__')
076 ->raw(",\n")
077 ;
078 }
079
080 $compiler
081 ->addIndentation()
082 ->string(self::VARARGS_NAME)
083 ->raw(' => ')
084 ;
085
086 if (PHP_VERSION_ID >= 50600) {
087 $compiler->raw("\$__varargs__,\n");
088 } else {
089 $compiler
090 ->raw('func_num_args() > ')
091 ->repr($count)
092 ->raw(' ? array_slice(func_get_args(), ')
093 ->repr($count)
094 ->raw(") : array(),\n")
095 ;
096 }
097
098 $compiler
099 ->outdent()
100 ->write("));\n\n")
101 ->write("\$blocks = array();\n\n")
102 ->write("ob_start();\n")
103 ->write("try {\n")
104 ->indent()
105 ->subcompile($this->getNode('body'))
106 ->outdent()
107 ->write("} catch (Exception \$e) {\n")
108 ->indent()
109 ->write("ob_end_clean();\n\n")
110 ->write("throw \$e;\n")
111 ->outdent()
112 ->write("} catch (Throwable \$e) {\n")
113 ->indent()
114 ->write("ob_end_clean();\n\n")
115 ->write("throw \$e;\n")
116 ->outdent()
117 ->write("}\n\n")
118 ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
119 ->outdent()
120 ->write("}\n\n")
121 ;
122 }
123 }
124