- A lot of bugfixes made for this release.

This commit is contained in:
mcndave committed 2021-02-16 03:17:32 +00:00
1 parent 4e909b2840
commit 8df38b568c
13 files changed
+159 -71

No files matched your search

+14 -17
View File
@@ -4,38 +4,35 @@ namespace Picea\Extension;
use Picea\Compiler\Context;
class JsonExtension implements Extension {
class JsonExtension implements Extension, FunctionExtension {
public array $token = [ "json", "json.pretty" ];
public int $flags = JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_THROW_ON_ERROR;
public function __construct(? Context $context = null) {
if ($context) {
$this->register($context);
}
}
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token)
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token)
{
$flag = $this->flags;
switch ($token) {
case "json.pretty":
$flag |= \JSON_PRETTY_PRINT;
break;
break;
case "json.html":
return "<?php echo htmlentities(json_encode($arguments, {$this->flags}), ENT_QUOTES, 'UTF-8') ?>";
}
return "<?php echo json_encode($arguments, $flag) ?>";
}
public function register(Context $context) : void
public function exportFunctions(): array
{
$context->pushFunction("json", function($arguments, ? int $flags = null) {
return json_encode($arguments, \JSON_FORCE_OBJECT);
});
return [
'json' => function($arguments, ? int $flags = null) {
return json_encode($arguments, \JSON_FORCE_OBJECT);
},
];
}
}