refactor database structure... moved db\manager back to system\db.php
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<?php namespace System\DB\Eloquent;
|
||||
|
||||
use System\DB;
|
||||
use System\Str;
|
||||
use System\Config;
|
||||
use System\Inflector;
|
||||
use System\Paginator;
|
||||
use System\DB\Manager;
|
||||
|
||||
abstract class Model {
|
||||
|
||||
@@ -135,7 +135,7 @@ abstract class Model {
|
||||
|
||||
// Since this method is only used for instantiating models for querying
|
||||
// purposes, we will go ahead and set the Query instance on the model.
|
||||
$model->query = Manager::connection(static::$connection)->table(static::table($class));
|
||||
$model->query = DB::connection(static::$connection)->table(static::table($class));
|
||||
|
||||
return $model;
|
||||
}
|
||||
@@ -367,7 +367,7 @@ abstract class Model {
|
||||
|
||||
// Since the model was instantiated using "new", a query instance has not been set.
|
||||
// Only models being used for querying have their query instances set by default.
|
||||
$this->query = Manager::connection(static::$connection)->table(static::table($model));
|
||||
$this->query = DB::connection(static::$connection)->table(static::table($model));
|
||||
|
||||
if (property_exists($model, 'timestamps') and $model::$timestamps)
|
||||
{
|
||||
@@ -416,7 +416,7 @@ abstract class Model {
|
||||
// delete statement to the query instance.
|
||||
if ( ! $this->exists) return $this->query->delete();
|
||||
|
||||
return Manager::connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id);
|
||||
return DB::connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php namespace System\DB;
|
||||
|
||||
use System\Config;
|
||||
|
||||
class Manager {
|
||||
|
||||
/**
|
||||
* The established database connections.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $connections = array();
|
||||
|
||||
/**
|
||||
* Get a database connection. If no database name is specified, the default
|
||||
* connection will be returned as defined in the db configuration file.
|
||||
*
|
||||
* Note: Database connections are managed as singletons.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return Connection
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a fluent query against a table.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $connection
|
||||
* @return Query
|
||||
*/
|
||||
public static function table($table, $connection = null)
|
||||
{
|
||||
return static::connection($connection)->table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method for calling methods on the default database connection.
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return call_user_func_array(array(static::connection(), $method), $parameters);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user