Skip to content

Commit

Permalink
Mark Table::__construct() as internal
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 22, 2024
1 parent e720715 commit 7a25c5d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
44 changes: 27 additions & 17 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,26 @@ public function listTables(): array
continue;
}

$tables[] = new Table(
$tableName,
$this->_getPortableTableColumnList($tableName, $database, $tableColumns),
$this->_getPortableTableIndexesList($indexColumnsByTable[$tableName] ?? [], $tableName),
[],
$this->_getPortableTableForeignKeysList($foreignKeyColumnsByTable[$tableName] ?? []),
$tableOptionsByTable[$tableName] ?? [],
$configuration,
);
$editor = Table::editor()
->setName($tableName)
->setColumns($this->_getPortableTableColumnList($tableName, $database, $tableColumns))
->setIndexes(
$this->_getPortableTableIndexesList($indexColumnsByTable[$tableName] ?? [], $tableName),
);

if (isset($foreignKeyColumnsByTable[$tableName])) {
$editor->setForeignKeyConstraints(
$this->_getPortableTableForeignKeysList($foreignKeyColumnsByTable[$tableName]),
);
}

if (isset($tableOptionsByTable[$tableName])) {
$editor->setOptions($tableOptionsByTable[$tableName]);
}

$tables[] = $editor
->setConfiguration($configuration)
->create();
}

return $tables;
Expand Down Expand Up @@ -328,14 +339,13 @@ public function introspectTable(string $name): Table
throw TableDoesNotExist::new($name);
}

return new Table(
$name,
$columns,
$this->listTableIndexes($name),
[],
$this->listTableForeignKeys($name),
$this->getTableOptions($name),
);
return Table::editor()
->setName($name)
->setColumns($columns)
->setIndexes($this->listTableIndexes($name))
->setForeignKeyConstraints($this->listTableForeignKeys($name))
->setOptions($this->getTableOptions($name))
->create();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ public function createNamespace(string $name): self
*/
public function createTable(string $name): Table
{
$table = new Table($name, [], [], [], [], [], $this->_schemaConfig->toTableConfiguration());
$this->_addTable($table);
$table = Table::editor()
->setName($name)
->setOptions($this->_schemaConfig->getDefaultTableOptions())
->setConfiguration($this->_schemaConfig->toTableConfiguration())
->create();

foreach ($this->_schemaConfig->getDefaultTableOptions() as $option => $value) {
$table->addOption($option, $value);
}
$this->_addTable($table);

return $table;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Table extends AbstractNamedObject
private int $maxIdentifierLength;

/**
* @internal Use {@link Table::editor()} to instantiate an editor and {@link TableEditor::create()}
* to create a table.
*
* @param array<Column> $columns
* @param array<Index> $indexes
* @param array<UniqueConstraint> $uniqueConstraints
Expand Down

0 comments on commit 7a25c5d

Please sign in to comment.