diff options
| author | winter | 2024-12-17 18:39:18 +0000 |
|---|---|---|
| committer | winter | 2024-12-17 18:39:18 +0000 |
| commit | 085762ec174eae1c519ec14db632f5ba197ed3c7 (patch) | |
| tree | 9ad49bc839b5f72ded47c119ff01a09dfa0b934a /Digitigrade/Model/FetchableModel.php | |
| parent | bc2cd99b108b8755a648c3915714e7c0e0771548 (diff) | |
hopefully implement push!
again i can't really test this yet because i don't have two https instances that can talk to each other.
soon i will set that up and test all these recent commits
Diffstat (limited to 'Digitigrade/Model/FetchableModel.php')
| -rw-r--r-- | Digitigrade/Model/FetchableModel.php | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Digitigrade/Model/FetchableModel.php b/Digitigrade/Model/FetchableModel.php index bd25d39..964ea15 100644 --- a/Digitigrade/Model/FetchableModel.php +++ b/Digitigrade/Model/FetchableModel.php @@ -13,15 +13,7 @@ abstract class FetchableModel extends Model implements RemoteFetchable { self::$mapper->bStrictObjectTypeChecking = false; } - protected static function fetchFromRemote(string $uri, bool $autoSave): ?static { - // fetch the object - // janky hack: if this is an Instance then avoid recursively fetching itself - $data = @get_remote_object_authenticated($uri, static::class == Instance::class); - if ($data === false) - return null; - $data = json_decode($data); - if ($data === null) - return null; + protected static function createFromJson(\stdClass $data, bool $autoSave): static { // default everything nullable to null $obj = new static(); $reflProps = (new \ReflectionClass(static::class))->getProperties(); @@ -67,6 +59,18 @@ abstract class FetchableModel extends Model implements RemoteFetchable { return $obj; } + protected static function fetchFromRemote(string $uri, bool $autoSave): ?static { + // fetch the object + // janky hack: if this is an Instance then avoid recursively fetching itself + $data = @get_remote_object_authenticated($uri, static::class == Instance::class); + if ($data === false) + return null; + $data = json_decode($data); + if ($data === null) + return null; + return static::createFromJson($data, $autoSave); + } + protected function finaliseAfterFetch(string $uri) { } |
