-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Schema\Column; | ||
|
||
use Yiisoft\Db\Expression\ExpressionInterface; | ||
use Yiisoft\Db\Schema\SchemaInterface; | ||
|
||
class BitColumnSchema extends AbstractColumnSchema | ||
{ | ||
public function __construct( | ||
string $type = SchemaInterface::TYPE_BIT, | ||
string|null $phpType = SchemaInterface::PHP_TYPE_INTEGER, | ||
) { | ||
parent::__construct($type, $phpType); | ||
} | ||
|
||
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 phpTypecast(mixed $value): int|null | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
return (int) $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters