- Addedd a new Money extension and a new Function token
This commit is contained in:
1 parent
48ecd9f7d9
commit
b08325049b
3 files changed
+89
No files matched your search
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\ControlStructure;
|
||||
|
||||
class FunctionToken implements ControlStructure {
|
||||
|
||||
public array $token = [ "function", "endfunction", "return" ];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||
switch($token) {
|
||||
case "function":
|
||||
return $this->printFunction($context, $arguments);
|
||||
|
||||
case "return":
|
||||
if ( empty($context->functions) ) {
|
||||
throw new \RuntimeException("A function return tag {% return %} was found without an opening {% function ... %} tag");
|
||||
}
|
||||
|
||||
return $this->printReturn($context, $arguments);
|
||||
|
||||
case "endfunction":
|
||||
if ( empty($context->functions) ) {
|
||||
throw new \RuntimeException("A function closing tag {% endfunction %} was found without an opening {% function ... %} tag");
|
||||
}
|
||||
|
||||
$context->functions--;
|
||||
|
||||
return $this->printEndFunction($context);
|
||||
}
|
||||
}
|
||||
|
||||
protected function printFunction($context, ?string $arguments) : string
|
||||
{
|
||||
$context->functions++;
|
||||
return "<?php function $arguments { ?>";
|
||||
}
|
||||
|
||||
protected function printReturn($context, ?string $arguments) : string
|
||||
{
|
||||
return "<?php return $arguments; ?>";
|
||||
}
|
||||
|
||||
protected function printEndFunction($context) : string
|
||||
{
|
||||
return "<?php } ?>";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user