blob: 8df8148c4b4abd431b76114afda2057dd2e28d0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
];
}
}
|