refactoring database.

This commit is contained in:
Taylor Otwell
2011-08-19 21:18:59 -05:00
parent bf0aaa3cc7
commit 9d2a76b26f
8 changed files with 35 additions and 64 deletions

View File

@@ -2,7 +2,7 @@
use Laravel\DB\Connector;
class Generic extends Connector {
class Callback extends Connector {
/**
* Establish a PDO database connection.
@@ -12,7 +12,7 @@ class Generic extends Connector {
*/
public function connect($config)
{
return new \PDO($config['driver'].':'.$config['dsn'], $config['username'], $config['password'], $this->options);
return call_user_func($config['connector']);
}
}

View File

@@ -5,12 +5,14 @@ class Factory {
/**
* Create a new database connector instance for a given driver.
*
* @param string $driver
* @param array $config
* @return Connector
*/
public static function make($driver)
public static function make($config)
{
switch ($driver)
if (isset($config['connector'])) return new Callback;
switch ($config['driver'])
{
case 'sqlite':
return new SQLite;
@@ -18,12 +20,11 @@ class Factory {
case 'mysql':
return new MySQL;
case 'postgres':
case 'pgsql':
return new Postgres;
default:
return new Generic;
}
throw new \Exception("Database configuration is invalid. Please verify your configuration.");
}
}