public function testInitialize() { Sabel_Db_Config::initialize(new TestDatabaseConfig()); $config = Sabel_Db_Config::get("configtest"); $this->assertEquals("localhost", $config["host"]); $this->assertEquals("mydb", $config["database"]); }
public function run() { clearstatcache(); $this->checkInputs(); $outputDir = RUN_BASE . DS . LIB_DIR_NAME . DS . "schema"; $this->defineEnvironment($this->arguments[0]); Sabel_Db_Config::initialize(new Config_Database()); $isAll = false; $tables = $this->getOutputTables(); if (isset($tables[0]) && strtolower($tables[0]) === "all") { $isAll = count($tables) === 1; } $tList = new TableListWriter($outputDir); foreach (Sabel_Db_Config::get() as $connectionName => $params) { Sabel_Db_Config::add($connectionName, $params); $db = Sabel_Db::createMetadata($connectionName); foreach ($db->getTableList() as $tblName) { if ($isAll || in_array($tblName, $tables, true)) { $writer = new Sabel_Db_Metadata_FileWriter($outputDir); $writer->write($db->getTable($tblName)); $this->success("generate Schema 'Schema_" . convert_to_modelname($tblName) . "'"); } $tList->add($connectionName, $tblName); } if (Sabel_Console::hasOption("l", $this->arguments)) { $tList->write($connectionName); } } }
/** * @param Sabel_Db_Driver $driver * * @throws Sabel_Db_Exception_Connection * @return Sabel_Db_Driver */ protected static function _connect(Sabel_Db_Driver $driver) { $connectionName = $driver->getConnectionName(); $names = Sabel_Db_Config::getConnectionNamesOfSameSetting($connectionName); foreach ($names as $name) { if (isset(self::$connections[$name])) { $driver->setConnection(self::$connections[$name]); return $driver; } } if (!isset(self::$connections[$connectionName])) { $result = $driver->connect(Sabel_Db_Config::get($connectionName)); if (is_string($result)) { throw new Sabel_Db_Exception_Connection($result); } else { self::$connections[$connectionName] = $result; } } $driver->setConnection(self::$connections[$connectionName]); return $driver; }