public final function setTable(string $table_class) : DatabaseInterface { if ($this->isImmutable()) { throw SchemaException::immutable(static::class); } if (!isset(class_implements($table_class)[TableInterface::class])) { throw SchemaException::invalidTable(TableInterface::class, $table_class); } if ($this->hasTable($table_class::getName())) { throw SchemaException::tableAlreadySet(static::class, $table_class); } $this->tables[$table_class::getName()] = $table_class; return $this; }
public final function setForeignKeyObject(ForeignKey $foreign_key) : TableInterface { if ($this->isImmutable()) { throw SchemaException::immutable(static::class); } if ($this->hasForeignKey($foreign_key->getName())) { throw SchemaException::foreignKeyAlreadySet(static::class, $foreign_key->getName()); } $missing = array_diff($foreign_key->getColumns(), array_keys($this->getColumns())); if ($missing !== []) { throw TableException::columnNotSet(static::class, implode(', ', $missing)); } $this->foreign_keys[$foreign_key->getName()] = $foreign_key; if (!$this->hasIndexWithColumns(...$foreign_key->getColumns())) { $this->setIndexObject(new Index($foreign_key->getName(), ...$foreign_key->getColumns())); } return $this; }