tweaking and refactoring the database connectors. added connectors to the container.
This commit is contained in:
parent
07f3f5d03c
commit
893acd8743
|
@ -39,6 +39,33 @@
|
|||
return new Routing\Caller($c, require APP_PATH.'filters'.EXT, CONTROLLER_PATH);
|
||||
}),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Laravel Database Connectors
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following components are used to establish PDO database connections
|
||||
| to the various database systems supported by Laravel. By resolving these
|
||||
| connectors out of the IoC container, new database systems may be added
|
||||
| by simply registering a connector.
|
||||
|
|
||||
*/
|
||||
|
||||
'laravel.database.connectors.sqlite' => function($c)
|
||||
{
|
||||
return new Database\Connectors\SQLite;
|
||||
},
|
||||
|
||||
'laravel.database.connectors.mysql' => function($c)
|
||||
{
|
||||
return new Database\Connectors\MySQL;
|
||||
},
|
||||
|
||||
'laravel.database.connectors.pgsql' => function($c)
|
||||
{
|
||||
return new Database\Connectors\Postgres;
|
||||
},
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Laravel Caching Components
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php namespace Laravel\Database;
|
||||
|
||||
use Laravel\IoC;
|
||||
use Laravel\Config;
|
||||
|
||||
class Manager {
|
||||
|
@ -56,27 +57,12 @@ public static function connection($connection = null)
|
|||
*/
|
||||
protected static function connect($config)
|
||||
{
|
||||
if (isset($config['connector'])) { return call_user_func($config['connector'], $config); }
|
||||
|
||||
switch ($config['driver'])
|
||||
if (isset($config['connector']))
|
||||
{
|
||||
case 'sqlite':
|
||||
$connector = new Connectors\SQLite;
|
||||
break;
|
||||
|
||||
case 'mysql':
|
||||
$connector = new Connectors\MySQL;
|
||||
break;
|
||||
|
||||
case 'pgsql':
|
||||
$connector = new Connectors\Postgres;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception("Database driver [{$config['driver']}] is not supported.");
|
||||
return call_user_func($config['connector'], $config);
|
||||
}
|
||||
|
||||
return $connector->connect($config);
|
||||
return IoC::container()->core("database.connectors.{$config['driver']}")->connect($config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue