-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBooleanColumn.php
40 lines (32 loc) · 945 Bytes
/
BooleanColumn.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
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Oracle\Column;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PhpType;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Schema\Column\AbstractColumn;
final class BooleanColumn extends AbstractColumn
{
protected const DEFAULT_TYPE = ColumnType::BOOLEAN;
public function dbTypecast(mixed $value): string|ExpressionInterface|null
{
return match ($value) {
true => '1',
false => '0',
null, '' => null,
default => $value instanceof ExpressionInterface ? $value : ($value ? '1' : '0'),
};
}
/** @psalm-mutation-free */
public function getPhpType(): string
{
return PhpType::BOOL;
}
public function phpTypecast(mixed $value): bool|null
{
if ($value === null) {
return null;
}
return $value && $value !== "\0";
}
}