-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathProjectContext.php
More file actions
64 lines (56 loc) · 1.8 KB
/
Copy pathProjectContext.php
File metadata and controls
64 lines (56 loc) · 1.8 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Appwrite\Event\Message;
use Utopia\Database\Document;
final readonly class ProjectContext
{
public function __construct(
public string $id = '',
public string $sequence = '',
public string $teamId = '',
public string $teamInternalId = '',
public string $createdAt = '',
public string $region = '',
) {
}
public static function fromDocument(Document $project): self
{
return new self(
id: $project->getId(),
sequence: (string) $project->getSequence(),
teamId: (string) $project->getAttribute('teamId', ''),
teamInternalId: (string) $project->getAttribute('teamInternalId', ''),
createdAt: (string) $project->getCreatedAt(),
region: (string) $project->getAttribute('region', ''),
);
}
public static function fromArray(array $project): self
{
return new self(
id: (string) ($project['$id'] ?? ''),
sequence: (string) ($project['$sequence'] ?? ''),
teamId: (string) ($project['teamId'] ?? ''),
teamInternalId: (string) ($project['teamInternalId'] ?? ''),
createdAt: (string) ($project['$createdAt'] ?? ''),
region: (string) ($project['region'] ?? ''),
);
}
public function isEmpty(): bool
{
return $this->id === '';
}
public function isConsole(): bool
{
return $this->id === 'console';
}
public function toArray(): array
{
return [
'$id' => $this->id,
'$sequence' => $this->sequence,
'teamId' => $this->teamId,
'teamInternalId' => $this->teamInternalId,
'$createdAt' => $this->createdAt,
'region' => $this->region,
];
}
}