blob: de3ff9de56e9625208f2d2c6de59f3e360054333 (
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
44
45
46
47
48
|
<?php
namespace Digitigrade\Model;
use Digitigrade\Model;
class Instance extends FetchableModel {
public ?int $id;
public string $domain;
public string $name;
public ?string $description;
public ?string $icon; // uri
public string $softwareName;
public ?string $softwareDescription;
public ?string $softwareVersion;
public ?string $softwareHomepage;
public InstanceEndpoints $endpoints;
protected function getUpdateWhereClause(\PDO $db): ?string {
if (self::findWhere('domain = ?', [$this->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, bool $autoSave = true, bool $forceRefetch = false): ?self {
return self::findByUri("https://$domain/.well-known/pawpub-instance", $autoSave, $forceRefetch);
}
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);
}
}
|