From 2713c1f73a39d4106936d4c52bf8f18d810d7f3c Mon Sep 17 00:00:00 2001 From: winter Date: Fri, 13 Dec 2024 23:53:23 +0000 Subject: add instance information --- Digitigrade/Model/Instance.php | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Digitigrade/Model/Instance.php (limited to 'Digitigrade/Model/Instance.php') diff --git a/Digitigrade/Model/Instance.php b/Digitigrade/Model/Instance.php new file mode 100644 index 0000000..2924f71 --- /dev/null +++ b/Digitigrade/Model/Instance.php @@ -0,0 +1,48 @@ +domain]) != null) + return 'domain = ' . $db->quote($this->domain); + if (self::findWhere('id = ?', [$this->id]) != null) + return "id = $this->id"; + return null; + } + + public static function findByDomain(string $domain): ?self { + return self::findByUri("https://$domain/.well-known/pawpub-instance"); + } + + public function hydrate() { + $this->endpoints = InstanceEndpoints::findWhere('instance_id = ?', [$this->id]); + } + + protected function beforeSave(string $uri) { + $this->domain = explode('/', $uri)[2]; + } + + public static function findByUri(string $uri, bool $autoSave = true, bool $forceRefetch = false): ?static { + if (!$forceRefetch) { + $domain = explode('/', $uri)[2]; + $obj = self::findWhere('domain = ?', [$domain]); + if ($obj != null) + return $obj; + } + return self::fetchFromRemote($uri, $autoSave); + } +} \ No newline at end of file -- cgit v1.3