-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathBitColumnSchema.php
44 lines (35 loc) · 948 Bytes
/
BitColumnSchema.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
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Schema\Column;
use Yiisoft\Db\Constant\PhpType;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Schema\SchemaInterface;
class BitColumnSchema extends AbstractColumnSchema
{
public function __construct(
string $type = SchemaInterface::TYPE_BIT,
) {
parent::__construct($type);
}
public function dbTypecast(mixed $value): int|string|ExpressionInterface|null
{
if (is_int($value)) {
return $value;
}
return match ($value) {
null, '' => null,
default => $value instanceof ExpressionInterface ? $value : (int) $value,
};
}
public function getPhpType(): string
{
return PhpType::INT;
}
public function phpTypecast(mixed $value): int|null
{
if ($value === null) {
return null;
}
return (int) $value;
}
}