- First task of v2 done, tokens can now have unlimited options attached to it
This commit is contained in:
1 parent
afeb8789b5
commit
acd9f8c72e
8 files changed
+82
-41
No files matched your search
@@ -6,21 +6,22 @@ use Picea\Compiler\Context;
|
||||
|
||||
class JsonExtension implements Extension, FunctionExtension {
|
||||
|
||||
public array $token = [ "json", "json.pretty", "json.html" ];
|
||||
public array $token = [ "json" ];
|
||||
|
||||
public int $flags = JSON_HEX_TAG | \JSON_HEX_QUOT | \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_UNICODE;
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token)
|
||||
{
|
||||
$opt = $context->tokenOptions($token);
|
||||
|
||||
$flag = $this->flags;
|
||||
|
||||
switch ($token) {
|
||||
case "json.pretty":
|
||||
$flag |= \JSON_PRETTY_PRINT;
|
||||
break;
|
||||
if ( in_array('pretty', $opt) ) {
|
||||
$flag |= \JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
case "json.html":
|
||||
return "<?php echo htmlentities(json_encode($arguments, $flag), ENT_QUOTES, 'UTF-8') ?>";
|
||||
if ( in_array('html', $opt) ) {
|
||||
return "<?php echo htmlentities(json_encode($arguments, $flag), ENT_QUOTES, 'UTF-8') ?>";
|
||||
}
|
||||
|
||||
$cls = static::class;
|
||||
|
||||
Reference in new issue
Block a user