0 follower

Final Class Yiisoft\Db\Pgsql\Column\Int4RangeColumn

InheritanceYiisoft\Db\Pgsql\Column\Int4RangeColumn » Yiisoft\Db\Pgsql\Column\AbstractRangeColumn » Yiisoft\Db\Schema\Column\AbstractColumn

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_TYPE \Yiisoft\Db\Pgsql\Constant\PgsqlColumnType::INT4RANGE Yiisoft\Db\Pgsql\Column\Int4RangeColumn

Method Details

Hide inherited methods

createRangeValue() protected method

protected Yiisoft\Db\Pgsql\Expression\Int4RangeValue createRangeValue ( string|null $lower, string|null $upper, boolean $includeLower, boolean $includeUpper )
$lower string|null
$upper string|null
$includeLower boolean
$includeUpper boolean

                protected function createRangeValue(?string $lower, ?string $upper, bool $includeLower, bool $includeUpper): Int4RangeValue
{
    $column = $this->getBoundColumn();
    return new Int4RangeValue(
        $column->phpTypecast($lower),
        $column->phpTypecast($upper),
        $includeLower,
        $includeUpper,
    );
}

            
dbTypecast() public method
public mixed dbTypecast ( mixed $value )
$value mixed

                public function dbTypecast(mixed $value): mixed
{
    if ($value === null
        || is_string($value)
        || $value instanceof ExpressionInterface) {
        return $value;
    }
    if (!is_array($value)) {
        $this->throwWrongTypeException(gettype($value));
    }
    if (array_keys($value) !== [0, 1]) {
        throw new InvalidArgumentException(
            'Value of range should be an array with two elements: lower and upper bounds.',
        );
    }
    [$lower, $upper] = $value;
    $boundColumn = $this->getBoundColumn();
    return '['
        . $this->prepareBoundValue($boundColumn->dbTypecast($lower))
        . ','
        . $this->prepareBoundValue($boundColumn->dbTypecast($upper))
        . ']';
}

            
getBoundColumn() protected method

protected Yiisoft\Db\Pgsql\Column\IntegerColumn getBoundColumn ( )

                protected function getBoundColumn(): IntegerColumn
{
    return RangeBoundColumnFactory::int4();
}

            
phpTypecast() public method
public mixed phpTypecast ( mixed $value )
$value mixed

                public function phpTypecast(mixed $value): mixed
{
    /**
     * @var string|null $value We expect `phpTypecast()` to only receive the value that the database returns, which
     * in this case is `null` or a `string`. To avoid extra checks.
     */
    if ($value === null || $value === 'empty') {
        return null;
    }
    if (!preg_match('/^(?P<open>\[|\()(?P<lower>[^,]*),(?P<upper>[^\)\]]*)(?P<close>\)|\])$/', $value, $matches)) {
        throw new NotSupportedException('Unsupported range format.');
    }
    return $this->createRangeValue(
        $matches['lower'] === '' ? null : trim($matches['lower'], '"'),
        $matches['upper'] === '' ? null : trim($matches['upper'], '"'),
        $matches['open'] === '[',
        $matches['close'] === ']',
    );
}