示例#1
0
 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']));
 }
示例#2
0
 /**
  * @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']);
         }
     }
 }
示例#3
0
 /**
  * @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);
     }
 }
示例#4
0
 /**
  * @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;
 }
示例#5
0
文件: DbInit.php 项目: sigma-z/dive
 /**
  * (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);
 }