0 follower

Abstract Class Yiisoft\Db\Pgsql\Column\AbstractRangeColumn

InheritanceYiisoft\Db\Pgsql\Column\AbstractRangeColumn » Yiisoft\Db\Schema\Column\AbstractColumn
SubclassesYiisoft\Db\Pgsql\Column\DateRangeColumn, Yiisoft\Db\Pgsql\Column\Int4RangeColumn, Yiisoft\Db\Pgsql\Column\Int8RangeColumn, Yiisoft\Db\Pgsql\Column\NumRangeColumn, Yiisoft\Db\Pgsql\Column\TsRangeColumn, Yiisoft\Db\Pgsql\Column\TsTzRangeColumn

Method Details

Hide inherited methods

createRangeValue() protected abstract method

protected abstract \Yiisoft\Db\Expression\ExpressionInterface createRangeValue ( string|null $lower, string|null $upper, boolean $includeLower, boolean $includeUpper )
$lower string|null
$upper string|null
$includeLower boolean
$includeUpper boolean
throws \Yiisoft\Db\Exception\NotSupportedException

                abstract protected function createRangeValue(
    ?string $lower,
    ?string $upper,
    bool $includeLower,
    bool $includeUpper,
): ExpressionInterface;

            
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 abstract method

protected abstract \Yiisoft\Db\Schema\Column\ColumnInterface getBoundColumn ( )

                abstract protected function getBoundColumn(): ColumnInterface;

            
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'] === ']',
    );
}