23 foreach ($arguments as $argumentName => $argument) {
24 if (self::VARARGS_NAME === $argumentName) {
25 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->getTemplateLine());
36 ->write(sprintf(
'public function get%s(', $this->
getAttribute(
'name')))
41 foreach ($this->
getNode(
'arguments') as
$name => $default) {
44 ->subcompile($default)
47 if (++$pos < $count) {
52 if (PHP_VERSION_ID >= 50600) {
57 $compiler->
raw(
'...$__varargs__');
67 ->
write(
"\$context = \$this->env->mergeGlobals(array(\n")
71 foreach ($this->
getNode(
'arguments') as
$name => $default) {
75 ->raw(
' => $__'.
$name.
'__')
82 ->string(self::VARARGS_NAME)
86 if (PHP_VERSION_ID >= 50600) {
87 $compiler->
raw(
"\$__varargs__,\n");
90 ->
raw(
'func_num_args() > ')
92 ->raw(
' ? array_slice(func_get_args(), ')
94 ->raw(
") : array(),\n")
101 ->write(
"\$blocks = array();\n\n")
102 ->write(
"ob_start();\n")
105 ->subcompile($this->
getNode(
'body'))
107 ->write(
"} catch (Exception \$e) {\n")
109 ->write(
"ob_end_clean();\n\n")
110 ->write(
"throw \$e;\n")
112 ->write(
"} catch (Throwable \$e) {\n")
114 ->write(
"ob_end_clean();\n\n")
115 ->write(
"throw \$e;\n")
118 ->write(
"return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
125 class_alias(
'Twig_Node_Macro',
'Twig\Node\MacroNode',
false);
raw($string)
Adds a raw string to the compiled code.
Represents a node in the AST.
outdent($step=1)
Outdents the generated code.
Represents a node in the AST.
__construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag=null)
Exception thrown when a syntax error occurs during lexing or parsing of a template.
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
Create styles array
The data for the language used.
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
write()
Writes a string to the compiled code by adding indentation.