Files
picea/src/ControlStructure/OrToken.php
T

24 lines
778 B
PHP

<?php
namespace Picea\ControlStructure;
class OrToken implements ControlStructure {
public string $token = "or";
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string {
if ( empty($context->iterationStack) ) {
throw new \LogicException("Token `or` was used outside of iterator. Make sure your `for`, `foreach`, `while`, `do/until` declaration are properly made.");
}
$key = count( $context->iterationStack ) - 1;
$context->iterationStack[$key]['or'] = true;
$name = $context->iterationStack[$key]['uid'];
return "<?php {$context->iterationStack[$key]['token']}; if( false === ($name ?? false) ): ?>";
}
}