-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathDatabase.php
More file actions
108 lines (100 loc) · 4.05 KB
/
Copy pathDatabase.php
File metadata and controls
108 lines (100 loc) · 4.05 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Appwrite\Models;
use Appwrite\Enums\DatabaseType;
/**
* Database
*/
readonly class Database
{
use ArraySerializable;
/**
* Database constructor.
*
* @param string $id database id.
* @param string $name database name.
* @param string $createdAt database creation date in iso 8601 format.
* @param string $updatedAt database update date in iso 8601 format.
* @param bool $enabled if database is enabled. can be 'enabled' or 'disabled'. when disabled, the database is inaccessible to users, but remains accessible to server sdks using api keys.
* @param DatabaseType $type database type.
* @param list<BackupPolicy> $policies database backup policies.
* @param list<BackupArchive> $archives database backup archives.
*/
public function __construct(
public string $id,
public string $name,
public string $createdAt,
public string $updatedAt,
public bool $enabled,
public DatabaseType $type,
public array $policies,
public array $archives
) {
}
/**
* @param array<string, mixed> $data
*/
public static function from(array $data): static
{
if (!array_key_exists('$id', $data)) {
throw new \InvalidArgumentException('Missing required field "$id" for ' . static::class . '.');
}
if (!array_key_exists('name', $data)) {
throw new \InvalidArgumentException('Missing required field "name" for ' . static::class . '.');
}
if (!array_key_exists('$createdAt', $data)) {
throw new \InvalidArgumentException('Missing required field "$createdAt" for ' . static::class . '.');
}
if (!array_key_exists('$updatedAt', $data)) {
throw new \InvalidArgumentException('Missing required field "$updatedAt" for ' . static::class . '.');
}
if (!array_key_exists('enabled', $data)) {
throw new \InvalidArgumentException('Missing required field "enabled" for ' . static::class . '.');
}
if (!array_key_exists('type', $data)) {
throw new \InvalidArgumentException('Missing required field "type" for ' . static::class . '.');
}
if (!array_key_exists('policies', $data)) {
throw new \InvalidArgumentException('Missing required field "policies" for ' . static::class . '.');
}
if (!array_key_exists('archives', $data)) {
throw new \InvalidArgumentException('Missing required field "archives" for ' . static::class . '.');
}
return new static(
id: $data['$id'],
name: $data['name'],
createdAt: $data['$createdAt'],
updatedAt: $data['$updatedAt'],
enabled: $data['enabled'],
type: static::hydrateTypedValue(DatabaseType::class, $data['type']),
policies: is_array($data['policies'])
? array_map(
static fn (mixed $item): mixed => static::hydrateTypedValue(BackupPolicy::class, $item),
$data['policies']
)
: $data['policies'],
archives: is_array($data['archives'])
? array_map(
static fn (mixed $item): mixed => static::hydrateTypedValue(BackupArchive::class, $item),
$data['archives']
)
: $data['archives']
);
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
$result = [
'$id' => static::serializeValue($this->id),
'name' => static::serializeValue($this->name),
'$createdAt' => static::serializeValue($this->createdAt),
'$updatedAt' => static::serializeValue($this->updatedAt),
'enabled' => static::serializeValue($this->enabled),
'type' => static::serializeValue($this->type),
'policies' => static::serializeValue($this->policies),
'archives' => static::serializeValue($this->archives)
];
return $result;
}
}