added setExpectedException and check type Config

This commit is contained in:
Vyacheslav Agafonov
2011-11-30 13:26:36 +04:00
parent b7e71c20b7
commit be83874392
4 changed files with 30 additions and 7 deletions

View File

@ -36,11 +36,14 @@ class Db
{
if (!isset(self::$connections[$name])) {
if (!$config) {
if (gettype(Config::get(__CLASS__)) != 'object') {
throw new InitializationException('config no object');
}
$config = Config::get(__CLASS__)->$name;
}
if (!is_array($config)) {
throw new GeneralException('Connection parameters must be an array');
throw new InitializationException('Connection parameters must be an array');
}
$driver = 'MySQLiDriver';
@ -52,7 +55,7 @@ class Db
$connection = new $driver($config);
if (!$connection instanceof DbDriver) {
throw new GeneralException('Database driver must extends DbDriver');
throw new InitializationException('Database driver must extends DbDriver');
}
self::$connections[$name] = $connection;
}