diff options
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) { } |
