diff options
Diffstat (limited to 'Digitigrade/Model/ExtensionObject.php')
| -rw-r--r-- | Digitigrade/Model/ExtensionObject.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Digitigrade/Model/ExtensionObject.php b/Digitigrade/Model/ExtensionObject.php new file mode 100644 index 0000000..8df8148 --- /dev/null +++ b/Digitigrade/Model/ExtensionObject.php @@ -0,0 +1,43 @@ +<?php +namespace Digitigrade\Model; + +class ExtensionObject extends PushableModel { + public ?int $id; + public string $uri; + public string $extension; + public \stdClass $data; + + protected function getUpdateWhereClause(\PDO $db): ?string { + if (self::findWhere('uri = ?', [$this->uri]) != null) + return 'uri = ' . $db->quote($this->uri); + if (self::findWhere('id = ?', [$this->id]) != null) + return "id = $this->id"; + return null; + } + + protected static function createFromJson(\stdClass $data, bool $autoSave, ?string $uri = null): static { + $obj = new static(); + $obj->uri = $data->self; + $obj->extension = $data->extension; + unset($data->self, $data->extension, $data->type); + $obj->data = clone $data; + $data->self = $obj->uri; + $data->extension = $obj->extension; + $data->type = 'extension'; + return $obj; + } + + public function getRelevantServers(): array { + // TODO + return []; + } + + public function jsonSerialize(): mixed { + return [ + 'type' => 'extension', + 'self' => path_to_uri("/extension/$this->id"), + 'extension' => $this->extension, + ...get_object_vars($this->data) + ]; + } +}
\ No newline at end of file |
