123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php namespace Laravel\Database;
- class Manager {
-
- public $connections = array();
-
- protected $connector;
-
- protected $config;
-
- protected $default;
-
- public function __construct(Connector\Factory $connector, $config, $default)
- {
- $this->config = $config;
- $this->default = $default;
- $this->connector = $connector;
- }
-
- public function connection($connection = null)
- {
- if (is_null($connection)) $connection = $this->default;
- if ( ! array_key_exists($connection, $this->connections))
- {
- if ( ! isset($this->config[$connection]))
- {
- throw new \Exception("Database connection [$connection] is not defined.");
- }
- list($connector, $query, $compiler) = array($this->connector->make($this->config[$connection]), new Query\Factory, new Query\Compiler\Factory);
- $this->connections[$connection] = new Connection($connector, $query, $compiler, $connection, $this->config[$connection]);
- }
- return $this->connections[$connection];
- }
-
- public function table($table, $connection = null)
- {
- return $this->connection($connection)->table($table);
- }
-
- public function __call($method, $parameters)
- {
- return call_user_func_array(array($this->connection(), $method), $parameters);
- }
- }
|