Final Class Yiisoft\Db\Pgsql\Column\Int4RangeColumn
| Inheritance | Yiisoft\Db\Pgsql\Column\Int4RangeColumn » Yiisoft\Db\Pgsql\Column\AbstractRangeColumn » Yiisoft\Db\Schema\Column\AbstractColumn |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| dbTypecast() | Yiisoft\Db\Pgsql\Column\AbstractRangeColumn | |
| phpTypecast() | Yiisoft\Db\Pgsql\Column\AbstractRangeColumn |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| createRangeValue() | Yiisoft\Db\Pgsql\Column\Int4RangeColumn | |
| getBoundColumn() | Yiisoft\Db\Pgsql\Column\Int4RangeColumn |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_TYPE | \Yiisoft\Db\Pgsql\Constant\PgsqlColumnType::INT4RANGE | Yiisoft\Db\Pgsql\Column\Int4RangeColumn |
Method Details
| 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,
);
}
| 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))
. ']';
}
| protected Yiisoft\Db\Pgsql\Column\IntegerColumn getBoundColumn ( ) |
protected function getBoundColumn(): IntegerColumn
{
return RangeBoundColumnFactory::int4();
}
| 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'] === ']',
);
}
Signup or Login in order to comment.