Migrations\View\Helper\MigrationHelper::attributes PHP Method

attributes() public method

Returns an array of attributes for a given table column
public attributes ( string $table, string $column ) : array
$table string Name of the table to retrieve columns for
$column string A column to retrieve attributes for
return array
    public function attributes($table, $column)
    {
        $tableSchema = $table;
        if (!$table instanceof Table) {
            $tableSchema = $this->schema($table);
        }
        $validOptions = ['length', 'limit', 'default', 'null', 'precision', 'scale', 'after', 'update', 'comment', 'unsigned', 'signed', 'properties', 'autoIncrement'];
        $attributes = [];
        $options = $tableSchema->column($column);
        foreach ($options as $_option => $value) {
            $option = $_option;
            switch ($_option) {
                case 'length':
                    $option = 'limit';
                    break;
                case 'unsigned':
                    $option = 'signed';
                    $value = (bool) (!$value);
                    break;
                case 'unique':
                    $value = (bool) $value;
                    break;
            }
            if (!in_array($option, $validOptions)) {
                continue;
            }
            $attributes[$option] = $value;
        }
        ksort($attributes);
        return $attributes;
    }