This commit is contained in:
Dave M. 2020-10-06 15:49:51 +00:00
commit 10632e9f67
4 changed files with 14 additions and 8 deletions

View File

@ -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[] = [

View File

@ -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 "<?php {$context->iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>";
}

View File

@ -11,7 +11,9 @@ class EchoRawToken implements Syntax {
public function parse(/*\Picae\Compiler\Context*/ &$content, string &$sourceCode)
{
$sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) {
return "<?php echo {$matches[2]} ?>";
$line = trim($matches[2], " \t\n\r\0\x0B;");
return "<?php echo {$line} ?>";
}, $sourceCode);
}

View File

@ -21,7 +21,9 @@ class EchoSafeToken implements Syntax {
public function parse(/*\Picae\Compiler\Context*/ &$context, string &$sourceCode)
{
$sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) {
return "<?php echo htmlspecialchars({$matches[2]}, {$this->flag}, '{$this->encoding}', " . ($this->doubleEncode ? "true" : "false") . ") ?>";
$line = trim($matches[2], " \t\n\r\0\x0B;");
return "<?php echo htmlspecialchars({$line}, {$this->flag}, '{$this->encoding}', " . ($this->doubleEncode ? "true" : "false") . ") ?>";
}, $sourceCode);
}