mootensai\enhancedgii\migration\Generator::getSchemaType PHP Метод

getSchemaType() публичный Метод

public getSchemaType ( ColumnSchema $column ) : array
$column yii\db\ColumnSchema
Результат array
    public function getSchemaType($column)
    {
        if ($this->constans === null) {
            $this->constans = [];
            $ref = new \ReflectionClass(Schema::className());
            foreach ($ref->getConstants() as $constName => $constValue) {
                if (strpos($constName, 'TYPE_') === 0) {
                    $this->constans[$constValue] = '$this->' . $constValue;
                }
            }
            $this->constans['smallint'] = '$this->smallInteger';
            $this->constans['bigint'] = '$this->bigInteger';
        }
        if ($column->type !== Schema::TYPE_BOOLEAN && $column->size !== null) {
            $size = [$column->size];
            if ($column->scale !== null) {
                $size[] = $column->scale;
            }
        } else {
            $size = [];
        }
        $result = '';
        if (isset($this->constans[$column->type])) {
            $result = $this->constans[$column->type] . '(' . implode(',', $size) . ')';
            if (!$column->allowNull) {
                $result .= '->notNull()';
            }
            if ($column->defaultValue !== null) {
                $default = is_string($column->defaultValue) ? "'" . addslashes($column->defaultValue) . "'" : $column->defaultValue;
                $result .= "->defaultValue({$default})";
            }
        } else {
            $result = $column->dbType;
            if (!empty($size)) {
                $result .= '(' . implode(',', $size) . ')';
            }
            if (!$column->allowNull) {
                $result .= ' NOT NULL';
            }
            if ($column->defaultValue !== null) {
                $default = is_string($column->defaultValue) ? "'" . addslashes($column->defaultValue) . "'" : $column->defaultValue;
                $result .= " DEFAULT {$default}";
            }
            $result = '"' . $result . '"';
        }
        return $result;
    }