- Fixed a recursivity bug with the OR token inside another foreach/or instance

This commit is contained in:
Dave Mc Nicoll 2020-05-20 15:32:08 -04:00
parent ce4ef6351a
commit 92e304daf3
2 changed files with 8 additions and 6 deletions

View File

@ -11,10 +11,14 @@ class ForeachToken implements ControlStructure {
case "foreach": case "foreach":
$name = "$".uniqid("foreach_"); $name = "$".uniqid("foreach_");
$count = count($context->iterationStack ?? []); $stack = array_filter($context->iterationStack ?? [], function($item) {
return ! $item['or'];
});
$count = count($stack);
if ( $count > 0 ) { if ( $count > 0 ) {
$name .= "[" . $context->iterationStack[$count - 1]['uid'] . "]"; $name .= "[" . end($stack)['uid'] . "]";
} }
$context->iterationStack[] = [ $context->iterationStack[] = [

View File

@ -12,13 +12,11 @@ class OrToken implements ControlStructure {
} }
$key = count( $context->iterationStack ) - 1; $key = count( $context->iterationStack ) - 1;
$context->iterationStack[$key]['or'] = true; $context->iterationStack[$key]['or'] = true;
$name = $context->iterationStack[$key]['uid']; $name = $context->iterationStack[$key]['uid'];
#if ($key !== 0) {
#}
return "<?php {$context->iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>"; return "<?php {$context->iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>";
} }