Abstract Class Yiisoft\Db\Pgsql\Column\AbstractRangeColumn
| Inheritance | Yiisoft\ |
|---|---|
| Subclasses | Yiisoft\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| dbTypecast() | Yiisoft\ |
|
| phpTypecast() | Yiisoft\ |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| createRangeValue() | Yiisoft\ |
|
| getBoundColumn() | Yiisoft\ |
Method Details
| protected abstract \ | ||
| $lower | ?string | |
| $upper | ?string | |
| $includeLower | boolean | |
| $includeUpper | boolean | |
| throws | \ |
|
|---|---|---|
abstract protected function createRangeValue(
?string $lower,
?string $upper,
bool $includeLower,
bool $includeUpper,
): ExpressionInterface;
| public string|\ | ||
| $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))
. ']';
}
| protected abstract \ |
abstract protected function getBoundColumn(): ColumnInterface;
| public ?\ | ||
| $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'] === ']',
);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.