aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
authorwinter2025-05-07 19:37:08 +0100
committerwinter2025-05-07 19:37:08 +0100
commita904294db09ccaa93a5b561e7cd177026010e601 (patch)
treee491028843b02fdbd5f647ea5b49adee2965ad7a /Digitigrade/Model
parent33a7ad8a141c65841267dc94cc5e5c5be109e03c (diff)
implement extension objects at a basic level
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/ExtensionObject.php43
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