123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php namespace System\DB;
- use System\Config;
- class Manager {
-
- public static $connections = array();
-
- public static function connection($connection = null)
- {
- if (is_null($connection))
- {
- $connection = Config::get('db.default');
- }
- if ( ! array_key_exists($connection, static::$connections))
- {
- if (is_null($config = Config::get('db.connections.'.$connection)))
- {
- throw new \Exception("Database connection [$connection] is not defined.");
- }
- static::$connections[$connection] = new Connection($connection, (object) $config, new Connector);
- }
- return static::$connections[$connection];
- }
-
- public static function table($table, $connection = null)
- {
- return static::connection($connection)->table($table);
- }
-
- public static function __callStatic($method, $parameters)
- {
- return call_user_func_array(array(static::connection(), $method), $parameters);
- }
- }
|