-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathBigIntColumnSchema.php
57 lines (47 loc) · 1.44 KB
/
BigIntColumnSchema.php
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
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Schema\Column;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Constant\GettypeResult;
use Yiisoft\Db\Constant\PhpType;
use Yiisoft\Db\Schema\SchemaInterface;
use function gettype;
use const PHP_INT_MAX;
use const PHP_INT_MIN;
class BigIntColumnSchema extends AbstractColumnSchema
{
public function __construct(
string $type = SchemaInterface::TYPE_BIGINT,
) {
parent::__construct($type);
}
public function dbTypecast(mixed $value): int|string|ExpressionInterface|null
{
return match (gettype($value)) {
GettypeResult::STRING => $value === '' ? null : (
$value <= PHP_INT_MAX && $value >= PHP_INT_MIN
? (int) $value
: $value
),
GettypeResult::NULL => null,
GettypeResult::INTEGER => $value,
GettypeResult::BOOLEAN => $value ? 1 : 0,
default => $value instanceof ExpressionInterface ? $value : (
($val = (string) $value) <= PHP_INT_MAX && $val >= PHP_INT_MIN
? (int) $val
: $val
),
};
}
public function getPhpType(): string
{
return PhpType::STRING;
}
public function phpTypecast(mixed $value): string|null
{
if ($value === null) {
return null;
}
return (string) $value;
}
}