aboutsummaryrefslogtreecommitdiffhomepage
path: root/WpfTest/Model/Actor.php
blob: eaef99c573ced63ca2bfd2391d6293f96d43b0fc (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
<?php
namespace WpfTest\Model;

use WpfTest\Model;

class Actor extends Model implements \JsonSerializable {
    public ?int $id;
    public string $uri;
    public bool $isLocal = false;
    public \DateTimeImmutable $created;
    public ?\DateTimeImmutable $modified;
    public ?string $homepage;
    public string $handle;
    public string $displayName;
    public ?string $avatar;
    public ?string $bio;
    public ?string $pronouns;
    public bool $automated = false;
    public bool $requestToFollow = false;
    public ActorEndpoints $endpoints;
    public array $extensions = [];

    public static function findLocalByHandle(string $handle): ?self {
        return self::findWhere('is_local = true AND handle = ?', [$handle]);
    }

    public function jsonSerialize(): array {
        return [
            'type' => 'actor',
            'self' => path_to_uri("/user/$this->handle"),
            'created' => $this->created?->format('c'),
            'modified' => $this->modified?->format('c'),
            'homepage' => path_to_uri("/$this->handle"),
            'handle' => $this->handle,
            'displayName' => $this->displayName,
            'bio' => $this->bio,
            'pronouns' => $this->pronouns,
            'automated' => $this->automated,
            'endpoints' => [
                'basicFeed' => path_to_uri("/user/$this->handle/basicFeed"),
                'fullFeed' => path_to_uri("/user/$this->handle/fullFeed")
            ]
        ];
    }
}