Created
July 21, 2023 13:01
-
-
Save Djourdain/07b78d2211138e76979cbbeaccdb0d8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace Types; | |
use Doctrine\DBAL\Types\Type; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
class Int4Range extends Type | |
{ | |
const INT_4_RANGE = "int4range"; | |
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | |
{ | |
return "int4range"; | |
} | |
public function canRequireSQLConversion(): bool | |
{ | |
return true; | |
} | |
public function convertToPHPValue($value, AbstractPlatform $platform) | |
{ | |
$separatorPosition = strpos($value, ","); | |
$min = (int)substr($value, 1, $separatorPosition); | |
$isMinIncluded = "[" == substr($value, 0, 1 ); | |
$max = (int)substr($value, $separatorPosition+1,-1); | |
$isMaxIncluded = "]" == substr($value, -1); | |
return [ | |
$isMinIncluded ? $min : $min + 1, | |
$isMaxIncluded ? $max : $max - 1, | |
]; | |
} | |
public function getName(): string | |
{ | |
return self::INT_4_RANGE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment