From 92e304daf3e671482b715ffecf6ae40abec007f0 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 20 May 2020 15:32:08 -0400 Subject: [PATCH] - Fixed a recursivity bug with the OR token inside another foreach/or instance --- src/ControlStructure/ForeachToken.php | 10 +++++++--- src/ControlStructure/OrToken.php | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ControlStructure/ForeachToken.php b/src/ControlStructure/ForeachToken.php index 454a21a..7326a5d 100644 --- a/src/ControlStructure/ForeachToken.php +++ b/src/ControlStructure/ForeachToken.php @@ -10,11 +10,15 @@ class ForeachToken implements ControlStructure { switch($token) { case "foreach": $name = "$".uniqid("foreach_"); - - $count = count($context->iterationStack ?? []); + + $stack = array_filter($context->iterationStack ?? [], function($item) { + return ! $item['or']; + }); + + $count = count($stack); if ( $count > 0 ) { - $name .= "[" . $context->iterationStack[$count - 1]['uid'] . "]"; + $name .= "[" . end($stack)['uid'] . "]"; } $context->iterationStack[] = [ diff --git a/src/ControlStructure/OrToken.php b/src/ControlStructure/OrToken.php index f562a41..beecda0 100644 --- a/src/ControlStructure/OrToken.php +++ b/src/ControlStructure/OrToken.php @@ -12,13 +12,11 @@ class OrToken implements ControlStructure { } $key = count( $context->iterationStack ) - 1; + $context->iterationStack[$key]['or'] = true; $name = $context->iterationStack[$key]['uid']; - #if ($key !== 0) { - #} - return "iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>"; }