This commit is contained in:
2023-10-04 13:32:30 +03:00
parent 215d238505
commit 1ca5f4e521
82 changed files with 519 additions and 1889 deletions
+6 -18
View File
@@ -11,6 +11,8 @@ class Record implements JsonSerializable
function __construct(
public string $id,
public string $schema,
public Status $status,
public System $_sys,
public RecordData $data,
public ?File $_file = null,
@@ -18,15 +20,13 @@ class Record implements JsonSerializable
{
}
public function toArray(): array
{
return \json_decode(\json_encode($this), true);
}
public function toDB(): array
{
return [
"id" => $this->id,
"status" => $this->status->value,
"schema" => $this->schema,
"_sys" => json_encode($this->_sys),
"_file" => json_encode($this->_file),
"data" => json_encode($this->data),
@@ -46,6 +46,8 @@ class Record implements JsonSerializable
return new Record(
id: $data->id,
schema: $data->schema,
status: Status::from($data->status),
_sys: System::fromArray(json_decode($data->_sys, true)),
data: new RecordData(json_decode($data->data, true)),
_file: $file,
@@ -58,20 +60,6 @@ class Record implements JsonSerializable
return $this;
}
public static function fromArray(array $data): Record
{
$file = null;
if (!empty($data["_file"])) {
$file = File::fromArray($data["_file"]);
}
return new Record(
id: $data["id"],
_sys: System::fromArray($data["_sys"]),
data: new RecordData($data["data"]),
_file: $file,
);
}
}