Commit 9d4d6e52 authored by Taylor Otwell's avatar Taylor Otwell

refactor database structure... moved db\manager back to system\db.php

parent 21a6040a
...@@ -26,7 +26,7 @@ return array( ...@@ -26,7 +26,7 @@ return array(
'Cookie' => 'System\\Cookie', 'Cookie' => 'System\\Cookie',
'Crypt' => 'System\\Crypt', 'Crypt' => 'System\\Crypt',
'Date' => 'System\\Date', 'Date' => 'System\\Date',
'DB' => 'System\\DB\\Manager', 'DB' => 'System\\DB',
'Eloquent' => 'System\\DB\\Eloquent\\Model', 'Eloquent' => 'System\\DB\\Eloquent\\Model',
'File' => 'System\\File', 'File' => 'System\\File',
'Form' => 'System\\Form', 'Form' => 'System\\Form',
......
<?php namespace System\DB; <?php namespace System;
use System\Config; class DB {
class Manager {
/** /**
* The established database connections. * The established database connections.
...@@ -18,7 +16,7 @@ class Manager { ...@@ -18,7 +16,7 @@ class Manager {
* Note: Database connections are managed as singletons. * Note: Database connections are managed as singletons.
* *
* @param string $connection * @param string $connection
* @return Connection * @return DB\Connection
*/ */
public static function connection($connection = null) public static function connection($connection = null)
{ {
...@@ -34,7 +32,7 @@ class Manager { ...@@ -34,7 +32,7 @@ class Manager {
throw new \Exception("Database connection [$connection] is not defined."); throw new \Exception("Database connection [$connection] is not defined.");
} }
static::$connections[$connection] = new Connection($connection, (object) $config, new Connector); static::$connections[$connection] = new DB\Connection($connection, (object) $config, new DB\Connector);
} }
return static::$connections[$connection]; return static::$connections[$connection];
...@@ -45,7 +43,7 @@ class Manager { ...@@ -45,7 +43,7 @@ class Manager {
* *
* @param string $table * @param string $table
* @param string $connection * @param string $connection
* @return Query * @return DB\Query
*/ */
public static function table($table, $connection = null) public static function table($table, $connection = null)
{ {
......
<?php namespace System\DB\Eloquent; <?php namespace System\DB\Eloquent;
use System\DB;
use System\Str; use System\Str;
use System\Config; use System\Config;
use System\Inflector; use System\Inflector;
use System\Paginator; use System\Paginator;
use System\DB\Manager;
abstract class Model { abstract class Model {
...@@ -135,7 +135,7 @@ abstract class Model { ...@@ -135,7 +135,7 @@ abstract class Model {
// Since this method is only used for instantiating models for querying // Since this method is only used for instantiating models for querying
// purposes, we will go ahead and set the Query instance on the model. // 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; return $model;
} }
...@@ -367,7 +367,7 @@ abstract class Model { ...@@ -367,7 +367,7 @@ abstract class Model {
// Since the model was instantiated using "new", a query instance has not been set. // 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. // 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) if (property_exists($model, 'timestamps') and $model::$timestamps)
{ {
...@@ -416,7 +416,7 @@ abstract class Model { ...@@ -416,7 +416,7 @@ abstract class Model {
// delete statement to the query instance. // delete statement to the query instance.
if ( ! $this->exists) return $this->query->delete(); 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);
} }
/** /**
......
<?php namespace System\Session; <?php namespace System\Session;
use System\Config; use System\Config;
use System\DB\Manager;
class DB implements Driver, Sweeper { class DB implements Driver, Sweeper {
...@@ -71,7 +70,7 @@ class DB implements Driver, Sweeper { ...@@ -71,7 +70,7 @@ class DB implements Driver, Sweeper {
*/ */
private function table() private function table()
{ {
return Manager::connection()->table(Config::get('session.table')); return \System\DB::connection()->table(Config::get('session.table'));
} }
} }
\ No newline at end of file
...@@ -302,7 +302,7 @@ class Validator { ...@@ -302,7 +302,7 @@ class Validator {
{ {
if ( ! isset($parameters[1])) $parameters[1] = $attribute; if ( ! isset($parameters[1])) $parameters[1] = $attribute;
return DB\Manager::connection()->table($parameters[0])->where($parameters[1], '=', $this->attributes[$attribute])->count() == 0; return DB::connection()->table($parameters[0])->where($parameters[1], '=', $this->attributes[$attribute])->count() == 0;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment