public function testToArray() { $tableNames = array_keys($this->schemaDefinition['tables']); $viewNames = array_keys($this->schemaDefinition['views']); $relationNames = array_keys($this->schemaDefinition['relations']); $actual = $this->schema->toArray(); $this->assertEquals($tableNames, array_keys($actual['tables'])); $this->assertEquals($viewNames, array_keys($actual['views'])); $this->assertEquals($relationNames, array_keys($actual['relations'])); }
/** * @param string $tableName */ private function initTableBehaviors($tableName) { $behaviors = $this->schema->getTableBehaviors($tableName); foreach ($behaviors as $behaviorDefinition) { $behavior = $this->getBehaviorInstance($behaviorDefinition); $this->getEventDispatcher()->addSubscriber($behavior); if (!empty($behaviorDefinition['config'])) { $behavior->setTableConfig($tableName, $behaviorDefinition['config']); } } }
/** * @param Schema $schema */ public function importFromSchema(Schema $schema) { $this->columns = $schema->getTableFields($this->tableName); $this->indexes = $schema->getTableIndexes($this->tableName); $foreignKeys = $schema->getTableRelations($this->tableName); /** @var array[] $owningRelations */ $owningRelations = $foreignKeys['owning']; foreach ($owningRelations as $definition) { $owningField = $definition['owningField']; $this->foreignKeys[$owningField] = array('refTable' => $definition['refTable'], 'refField' => $definition['refField'], 'onDelete' => isset($definition['onDelete']) ? $definition['onDelete'] : null, 'onUpdate' => isset($definition['onUpdate']) ? $definition['onUpdate'] : null); } }
/** * @param string $modelClassName * @param Schema $schema * @return string */ private function getTableName($modelClassName, Schema $schema) { $tableNames = $schema->getTableNames(); foreach ($tableNames as $tableName) { if ($modelClassName == $schema->getRecordClass($tableName)) { return $tableName; } } return null; }
/** * (re)create view * * @param PlatformInterface $platform * @param string $viewName */ private function createView(PlatformInterface $platform, $viewName) { $sqlStatement = $this->schema->getViewStatement($viewName); $sql = $platform->getCreateViewSql($viewName, $sqlStatement); $this->conn->exec($sql); }