aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template/twig/node
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-06-23 22:28:39 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2013-06-23 22:28:39 -0500
commit62fda07dd4f0ded73d16e9164b377c5e90fd4fd0 (patch)
treef7c721029acd2fee434f0862864f61d249038b36 /phpBB/includes/template/twig/node
parent93d94d5cbe5bd8a713fbfca46d8e44fde169cd19 (diff)
downloadforums-62fda07dd4f0ded73d16e9164b377c5e90fd4fd0.tar
forums-62fda07dd4f0ded73d16e9164b377c5e90fd4fd0.tar.gz
forums-62fda07dd4f0ded73d16e9164b377c5e90fd4fd0.tar.bz2
forums-62fda07dd4f0ded73d16e9164b377c5e90fd4fd0.tar.xz
forums-62fda07dd4f0ded73d16e9164b377c5e90fd4fd0.zip
[feature/twig] Changing method for begin node to not use anonymous function
The way it was setup would actually require PHP 5.4, which isn't an option right now. Leaving the old code there, just commented out, for now at least. PHPBB3-11598
Diffstat (limited to 'phpBB/includes/template/twig/node')
-rw-r--r--phpBB/includes/template/twig/node/begin.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/phpBB/includes/template/twig/node/begin.php b/phpBB/includes/template/twig/node/begin.php
index 3adb09f17e..34fd16dd73 100644
--- a/phpBB/includes/template/twig/node/begin.php
+++ b/phpBB/includes/template/twig/node/begin.php
@@ -30,6 +30,49 @@ class phpbb_template_twig_node_begin extends Twig_Node
*/
public function compile(Twig_Compiler $compiler)
{
+ $compiler
+ ->write("if (!isset(\$phpbb_blocks)) {\n")
+ ->indent()
+ ->write("\$phpbb_blocks = array();\n")
+ ->write("\$parent = \$context['_phpbb_blocks'];\n")
+ ->outdent()
+ ->write("}\n")
+ ->write("\$phpbb_blocks[] = '" . $this->getAttribute('beginName') . "';\n")
+ ;
+
+ $compiler
+ ->write("foreach (\$parent['" . $this->getAttribute('beginName') . "'] as \$" . $this->getAttribute('beginName') . ") {\n")
+ ->indent()
+ // Set up $context correctly so that Twig can get the correct data with $this->getAttribute
+ ->write("\$this->getEnvironment()->context_recursive_loop_builder(\$" . $this->getAttribute('beginName') . ", \$phpbb_blocks, \$context);\n")
+
+ // We store the parent so that we can do this recursively
+ ->write("\$parent = \$" . $this->getAttribute('beginName') . ";\n")
+ ;
+
+ $compiler->subcompile($this->getNode('body'));
+
+ $compiler
+ ->outdent()
+ ->write("}\n")
+
+ // Remove the last item from the blocks storage as we've completed iterating over them all
+ ->write("array_pop(\$phpbb_blocks);\n")
+
+ // If we've gone through all of the blocks, we're back at the main level and have completed, so unset the var
+ ->write("if (empty(\$phpbb_blocks)) { unset(\$phpbb_blocks); }\n")
+ ;
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * Uses anonymous functions to compile the loops, which seems nicer to me, but requires PHP 5.4 (since subcompile uses $this, which is not available in 5.3)
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ *
+ public function compile(Twig_Compiler $compiler)
+ {
$compiler->addDebugInfo($this);
$compiler
@@ -85,4 +128,5 @@ class phpbb_template_twig_node_begin extends Twig_Node
->outdent()
->write("}\n");
}
+ */
}