-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDatabase.php
More file actions
104 lines (92 loc) · 2.42 KB
/
Database.php
File metadata and controls
104 lines (92 loc) · 2.42 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
<?php
namespace Utopia\Migration\Resources\Database;
use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;
const TYPE_STRING = 'string';
const TYPE_INTEGER = 'integer';
const TYPE_FLOAT = 'float';
const TYPE_BOOLEAN = 'boolean';
const TYPE_OBJECT = 'object';
const TYPE_ARRAY = 'array';
const TYPE_NULL = 'null';
const TYPE_POINT = 'point';
const TYPE_LINE = 'linestring';
const TYPE_POLYGON = 'polygon';
class Database extends Resource
{
public function __construct(
string $id = '',
private readonly string $name = '',
protected string $createdAt = '',
protected string $updatedAt = '',
protected bool $enabled = true,
protected string $originalId = '',
protected string $type = '',
protected string $database = ''
) {
$this->id = $id;
}
/**
* @param array{
* id: string,
* name: string,
* createdAt: string,
* updatedAt: string,
* enabled: bool,
* originalId: string|null,
* database: string
* } $array
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['name'],
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
enabled: $array['enabled'] ?? true,
originalId: $array['originalId'] ?? '',
type: $array['type'] ?? 'legacy',
database: $array['database'] ?? ''
);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
'enabled' => $this->enabled,
'type' => $this->type,
'database' => $this->database
];
}
public static function getName(): string
{
return Resource::TYPE_DATABASE;
}
public function getGroup(): string
{
return Transfer::GROUP_DATABASES;
}
public function getDatabaseName(): string
{
return $this->name;
}
public function getEnabled(): bool
{
return $this->enabled;
}
public function getType(): string
{
return $this->type;
}
public function getDatabase(): string
{
return $this->database;
}
}