-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBigInt.php
More file actions
108 lines (100 loc) · 2.72 KB
/
BigInt.php
File metadata and controls
108 lines (100 loc) · 2.72 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 Utopia\Migration\Resources\Database\Columns;
use Utopia\Migration\Resources\Database\Column;
use Utopia\Migration\Resources\Database\Table;
class BigInt extends Column
{
public function __construct(
string $key,
Table $table,
bool $required = false,
?int $default = null,
bool $array = false,
?int $min = null,
?int $max = null,
bool $signed = true,
string $createdAt = '',
string $updatedAt = ''
) {
$min ??= PHP_INT_MIN;
$max ??= PHP_INT_MAX;
$size = 8;
parent::__construct(
$key,
$table,
size: $size,
required: $required,
default: $default,
array: $array,
signed: $signed,
formatOptions: [
'min' => $min,
'max' => $max,
],
createdAt: $createdAt,
updatedAt: $updatedAt
);
}
/**
* @param array{
* key: string,
* collection?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* documentSecurity: bool,
* permissions: ?array<string>
* },
* table?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* rowSecurity: bool,
* permissions: ?array<string>
* },
* required: bool,
* array: bool,
* default: ?int,
* formatOptions: array{
* min: ?int,
* max: ?int
* },
* createdAt: string,
* updatedAt: string,
* } $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['key'],
Table::fromArray($array['table'] ?? $array['collection']),
required: $array['required'],
default: $array['default'],
array: $array['array'],
min: $array['formatOptions']['min'] ?? null,
max: $array['formatOptions']['max'] ?? null,
signed: $array['signed'] ?? true,
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}
public function getType(): string
{
return Column::TYPE_BIG_INT;
}
public function getMin(): ?int
{
return (int)$this->formatOptions['min'];
}
public function getMax(): ?int
{
return (int)$this->formatOptions['max'];
}
}