- Added a new {% block ... %} token

- Added a new {% php ... %} token
- Fixed a bug with an OR if foreach is empty
This commit is contained in:
Dave Mc Nicoll committed 2020-03-30 12:13:02 -04:00
1 parent 0e201b77f2
commit 404d1f4359
9 files changed
+143 -22

No files matched your search

+10 -4
View File
@@ -7,14 +7,20 @@ class ForeachToken implements ControlStructure {
public string $token = "foreach";
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
$uid = "$".uniqid("foreach_");
$name = "$".uniqid("foreach_");
$count = count($context->iterationStack ?? []);
if ( $count > 0 ) {
$name .= "[" . $context->iterationStack[$count - 1]['uid'] . "]";
}
$context->iterationStack[] = [
'or' => false,
'uid' => $uid,
'uid' => $name,
'token' => 'endforeach',
];
return "<?php foreach ($arguments): {$uid} = 1; ?>";
return "<?php foreach ($arguments): $name = ( $name ?? 0 ) + 1; ; ?>";
}
}