init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Record;
|
||||
|
||||
use Lucent\LucentException;
|
||||
|
||||
class QueryRecord
|
||||
{
|
||||
|
||||
function __construct(
|
||||
public string $id,
|
||||
public System $_sys,
|
||||
public RecordData $data,
|
||||
public bool $isRoot,
|
||||
public ?File $_file = null,
|
||||
public array $_children = [],
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return json_decode(json_encode($this), true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public static function fromArray(array $data): QueryRecord
|
||||
{
|
||||
|
||||
|
||||
return new QueryRecord(
|
||||
id: $data["id"],
|
||||
_sys: System::fromArray($data["_sys"]),
|
||||
data: new RecordData($data["data"]),
|
||||
isRoot: $data["isRoot"] ?? false,
|
||||
_file: $data["_file"] ? new File(...$data["_file"]) : null,
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromRecord(Record $record): QueryRecord
|
||||
{
|
||||
return new QueryRecord(
|
||||
id: $record->id,
|
||||
_sys: $record->_sys,
|
||||
data: $record->data,
|
||||
isRoot: false,
|
||||
_file: $record->_file,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user