Final Class Yiisoft\Db\Pgsql\Column\ColumnDefinitionParser
| Inheritance | Yiisoft\Db\Pgsql\Column\ColumnDefinitionParser » Yiisoft\Db\Syntax\ColumnDefinitionParser |
|---|
Parses column definition string. For example, string(255) or int unsigned.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| parse() | Yiisoft\Db\Pgsql\Column\ColumnDefinitionParser |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| TYPE_PATTERN | '/^(?:(' . 'time(?:stamp)?\s*(?:\((\d+)\))? with(?:out)? time zone' . ')|(' . '(?:character|bit) varying' . '|double precision' . '|\w*' . ")(?:\\(((?:'[^']*'|[^)])+)\\))?)(\\[[\\d\\[\\]]*\\])?\\s*/i" | Yiisoft\Db\Pgsql\Column\ColumnDefinitionParser |
Method Details
| public array parse ( string $definition ) | ||
| $definition | string | |
public function parse(string $definition): array
{
preg_match(self::TYPE_PATTERN, $definition, $matches);
/** @var string $type */
$type = $matches[3] ?? preg_replace('/\s*\(\d+\)/', '', $matches[1]);
$type = strtolower($type);
$info = ['type' => $type];
$typeDetails = $matches[4] ?? $matches[2] ?? '';
if ($typeDetails !== '') {
if ($type === 'enum') {
$info += $this->enumInfo($typeDetails);
} else {
$info += $this->sizeInfo($typeDetails);
}
}
if (isset($matches[5])) {
/** @psalm-var positive-int */
$info['dimension'] = substr_count($matches[5], '[');
}
$extra = substr($definition, strlen($matches[0]));
return $info + $this->extraInfo($extra);
}
Signup or Login in order to comment.