public function getSchema($tables = null) { if ($tables == null) { $tables = $this->getTables(); } $schema = []; foreach ($tables as $tableName) { $fields = $this->getFields($tableName); $table = new Table($tableName, $fields); foreach ($this->getForeignKeyConstraints($tableName) as $fk) { $field = $table->getField($fk['field']); if ($field != null) { $field->setForeign($fk['on'], $fk['references'], $fk['name']); } } $schema[] = $table; } return $schema; }
/** * @param Field $field * @param bool $isDrop * @return string */ private function getForeignKeyName(Field $field, $isDrop = false) { $foreign = $field->getForeign(); $name = $field->getName(); if (!empty($foreign->getName())) { $name = $foreign->getName(); } if ($isDrop && empty($foreign->getName())) { $name = str_replace(array('-', '.'), '_', sprintf("%s_%s_foreign", $this->table->getName(), $field->getName())); } return $name; }
/** * Get entity name for the table. * * @param Table $table * @return string */ public function getEntity(Table $table) { return strtolower(str_singular($table->getName())); }