/** * @param ChangedTable $changedTable * @param Column $column */ private function addChangedColumn(ChangedTable $changedTable, Column $column) { if (!$changedTable->hasNewColumn($column->getName())) { $changedTable->addChangedColumn($column); } if (!$column->getNextColumn()) { return; } $this->addChangedColumn($changedTable, $column->getNextColumn()); }
/** * @param Table $table */ public function parseColumns(Table $table) { preg_match_all(RegExpPattern::column(), $table->getDefinition(), $matches); $lastColumn = null; for ($i = 0; $i < count($matches[0]); $i++) { $columnName = $matches['columnName'][$i]; $columnType = $matches['columnType'][$i]; $intLength = $matches['intLength'][$i]; $decimalLength = $matches['decimalLength'][$i]; $doubleLength = $matches['doubleLength'][$i]; $floatLength = $matches['floatLength'][$i]; $charLength = $matches['charLength'][$i]; $binaryLength = $matches['binaryLength'][$i]; $yearLength = $matches['yearLength'][$i]; $decimalPrecision = $matches['decimalPrecision'][$i]; $doublePrecision = $matches['doublePrecision'][$i]; $floatPrecision = $matches['floatPrecision'][$i]; $nullable = $matches['nullable'][$i]; $autoIncrement = $matches['autoIncrement'][$i]; $defaultValue = $matches['defaultValue'][$i]; $onUpdateValue = $matches['onUpdateValue'][$i]; $comment = $matches['comment'][$i]; $characterSet = $matches['characterSet'][$i]; $collate = $matches['collate'][$i]; $column = new Column($columnName); $column->setColumnType($columnType); preg_match(RegExpPattern::dataType(), $columnType, $dataTypeMatches); $dataType = $dataTypeMatches['dataType']; $unsigned = isset($dataTypeMatches['unsigned']) && !empty($dataTypeMatches['unsigned']); $column->setDataType($dataType); $column->setUnsigned($unsigned); $column->setLength($this->getColumnLength($intLength, $decimalLength, $doubleLength, $floatLength, $charLength, $binaryLength, $yearLength)); $column->setPrecision($this->getColumnPrecision($decimalPrecision, $doublePrecision, $floatPrecision)); $column->setNullable($nullable != 'NOT NULL'); $column->setAutoIncrement(!empty($autoIncrement)); if (!empty($defaultValue)) { $column->setDefaultValue($defaultValue); } if (!empty($onUpdateValue)) { $column->setOnUpdateValue($onUpdateValue); } if (!empty($comment)) { $column->setComment(str_replace('\'\'', '\'', $comment)); } if (!empty($characterSet)) { $column->setCharacterSet($characterSet); } if (!empty($collate)) { $column->setCollate($collate); } $column->setPrimaryKey(false); if ($lastColumn instanceof Column) { $column->setPreviousColumn($lastColumn); $lastColumn->setNextColumn($column); } $column->setOrder($i); $table->addColumn($column); $lastColumn = $column; } }