Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
MacroNode.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) 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 namespace Twig\Node;
013
014 use Twig\Compiler;
015 use Twig\Error\SyntaxError;
016
017 /**
018 * Represents a macro node.
019 *
020 * @author Fabien Potencier <fabien@symfony.com>
021 */
022 class MacroNode extends Node
023 {
024 public const VARARGS_NAME = 'varargs';
025
026 public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null)
027 {
028 foreach ($arguments as $argumentName => $argument) {
029 if (self::VARARGS_NAME === $argumentName) {
030 throw new SyntaxError(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->getTemplateLine(), $argument->getSourceContext());
031 }
032 }
033
034 parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag);
035 }
036
037 public function compile(Compiler $compiler)
038 {
039 $compiler
040 ->addDebugInfo($this)
041 ->write(sprintf('public function macro_%s(', $this->getAttribute('name')))
042 ;
043
044 $count = \count($this->getNode('arguments'));
045 $pos = 0;
046 foreach ($this->getNode('arguments') as $name => $default) {
047 $compiler
048 ->raw('$__'.$name.'__ = ')
049 ->subcompile($default)
050 ;
051
052 if (++$pos < $count) {
053 $compiler->raw(', ');
054 }
055 }
056
057 if ($count) {
058 $compiler->raw(', ');
059 }
060
061 $compiler
062 ->raw('...$__varargs__')
063 ->raw(")\n")
064 ->write("{\n")
065 ->indent()
066 ->write("\$macros = \$this->macros;\n")
067 ->write("\$context = \$this->env->mergeGlobals([\n")
068 ->indent()
069 ;
070
071 foreach ($this->getNode('arguments') as $name => $default) {
072 $compiler
073 ->write('')
074 ->string($name)
075 ->raw(' => $__'.$name.'__')
076 ->raw(",\n")
077 ;
078 }
079
080 $compiler
081 ->write('')
082 ->string(self::VARARGS_NAME)
083 ->raw(' => ')
084 ;
085
086 $compiler
087 ->raw("\$__varargs__,\n")
088 ->outdent()
089 ->write("]);\n\n")
090 ->write("\$blocks = [];\n\n")
091 ;
092 if ($compiler->getEnvironment()->isDebug()) {
093 $compiler->write("ob_start();\n");
094 } else {
095 $compiler->write("ob_start(function () { return ''; });\n");
096 }
097 $compiler
098 ->write("try {\n")
099 ->indent()
100 ->subcompile($this->getNode('body'))
101 ->raw("\n")
102 ->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n")
103 ->outdent()
104 ->write("} finally {\n")
105 ->indent()
106 ->write("ob_end_clean();\n")
107 ->outdent()
108 ->write("}\n")
109 ->outdent()
110 ->write("}\n\n")
111 ;
112 }
113 }
114
115 class_alias('Twig\Node\MacroNode', 'Twig_Node_Macro');
116