Add save to json/yaml (ctrl-w)
This commit is contained in:
@@ -27,5 +27,10 @@ class ArrayNode extends Node implements CollapsibleNode
|
||||
return new ArrayNode($items);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_values($this->items);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace NoccyLabs\JEdit\Tree;
|
||||
|
||||
abstract class Node
|
||||
use JsonSerializable;
|
||||
|
||||
abstract class Node implements JsonSerializable
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -29,5 +29,10 @@ class ObjectNode extends Node implements CollapsibleNode
|
||||
return new ObjectNode($properties);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,18 @@ class Tree
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function save(): mixed
|
||||
{
|
||||
if (!$this->root)
|
||||
return null;
|
||||
|
||||
return json_decode(
|
||||
json_encode(
|
||||
$this->root
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function parseNode(mixed $node): Node
|
||||
{
|
||||
if (is_array($node) && array_is_list($node)) {
|
||||
|
||||
@@ -7,5 +7,10 @@ class ValueNode extends Node
|
||||
public function __construct(public mixed $value)
|
||||
{
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user