示例#1
0
文件: Schema.php 项目: rzajac/schema
 /**
  * Get create statements string.
  *
  * @param string $format The format of the file: self::FORMAT_*
  *
  * @throws SchemaException
  *
  * @return array|string
  */
 public function getCreateStatements($format = null)
 {
     $exportType = Arr::get($this->config, self::CONFIG_KEY_EXPORT_FORMAT);
     // Override format from config.
     if ($format != null) {
         $exportType = $format;
     }
     $aine = Arr::get($this->config, self::CONFIG_KEY_AINE, false);
     $createStatements = [];
     $tableNames = array_merge($this->db->dbGetTableNames(), $this->db->dbGetViewNames());
     foreach ($tableNames as $tableName) {
         $table = $this->db->dbGetTableDefinition($tableName);
         $createStatements[$table->getName()] = $table->getCreateStatement($aine);
     }
     $ret = null;
     switch ($exportType) {
         case self::FORMAT_PHP_ARRAY:
             $ret = $createStatements;
             break;
         case self::FORMAT_PHP_FILE:
             $createStatements = array_map(['\\Kicaj\\Tools\\Helper\\Str', 'oneLine'], $createStatements);
             $configArray = var_export($createStatements, true);
             $ret = "<?php\n\n" . '$createStatements = ' . $configArray . ";\n\n";
             $ret .= 'return $createStatements;' . "\n";
             break;
         case self::FORMAT_SQL:
             $createStatements = array_map(['\\Kicaj\\Tools\\Helper\\Str', 'oneLine'], array_values($createStatements));
             $ret = implode("\n", array_values($createStatements)) . "\n";
             break;
         default:
             throw new SchemaException('unknown format: ' . $exportType);
     }
     return $ret;
 }
示例#2
0
 public function setUp()
 {
     Db::_resetInstances();
     $this->schema = Schema::make($this->getSchemaConfig('SCHEMA1'));
 }
示例#3
0
文件: Db_Test.php 项目: rzajac/schema
 /**
  * @covers ::dbGetTableNames
  *
  * @expectedException \Kicaj\Schema\SchemaException
  * @expectedExceptionMessage Table 'testschemalib.not_existing' doesn't exist
  */
 public function test_dbGetTableDefinition_error()
 {
     // Given
     $db = Db::factory(self::getSchemaConfig('SCHEMA1'));
     // Then
     $db->dbGetTableDefinition('not_existing');
 }