schmunk42\giiant\generators\test\Generator::generateAttributes PHP Метод

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

public generateAttributes ( $table ) : array
$table Table schema
Результат array Attributes containing all required model's information for test generator
    public function generateAttributes($table)
    {
        $labels = $this->generateLabels($table);
        $attributes = [];
        foreach ($table->columns as $column) {
            $label = $column->name;
            if (isset($labels[$column->name])) {
                $label = $labels[$column->name];
            }
            $attribute = [];
            $attribute['name'] = $column->name;
            $attribute['null'] = $column->allowNull;
            $attribute['size'] = $column->size;
            $attribute['primary'] = $column->isPrimaryKey;
            $attribute['label'] = $label;
            if ($column->autoIncrement) {
                $attribute['autoincrement'] = 'true';
            }
            if (!$column->allowNull && $column->defaultValue === null) {
                $attribute['required'] = 'true';
            }
            switch ($column->type) {
                case Schema::TYPE_SMALLINT:
                case Schema::TYPE_INTEGER:
                case Schema::TYPE_BIGINT:
                    $attribute['type'] = 'integer';
                    break;
                case Schema::TYPE_BOOLEAN:
                    $attribute['type'] = 'boolean';
                    break;
                case Schema::TYPE_FLOAT:
                case 'double':
                    // Schema::TYPE_DOUBLE, which is available since Yii 2.0.3
                // Schema::TYPE_DOUBLE, which is available since Yii 2.0.3
                case Schema::TYPE_DECIMAL:
                case Schema::TYPE_MONEY:
                    $attribute['type'] = 'number';
                    break;
                case Schema::TYPE_DATE:
                    $attribute['type'] = 'date';
                case Schema::TYPE_TIME:
                    $attribute['type'] = 'time';
                case Schema::TYPE_DATETIME:
                    $attribute['type'] = 'datetime';
                case Schema::TYPE_TIMESTAMP:
                    $attribute['type'] = 'timestamp';
                    break;
                default:
                    // strings
                    $attribute['type'] = 'string';
            }
            $attributes[] = $attribute;
        }
        return $attributes;
    }