refactor database structure... moved db\manager back to system\db.php
This commit is contained in:
parent
21a6040a79
commit
9d4d6e52bd
|
@ -26,7 +26,7 @@
|
||||||
'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',
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php namespace System\DB;
|
<?php namespace System;
|
||||||
|
|
||||||
use System\Config;
|
class DB {
|
||||||
|
|
||||||
class Manager {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The established database connections.
|
* The established database connections.
|
||||||
|
@ -17,8 +15,8 @@ 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 @@ public static function connection($connection = null)
|
||||||
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];
|
||||||
|
@ -43,9 +41,9 @@ public static function connection($connection = null)
|
||||||
/**
|
/**
|
||||||
* Begin a fluent query against a table.
|
* Begin a fluent query against a table.
|
||||||
*
|
*
|
||||||
* @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)
|
||||||
{
|
{
|
|
@ -1,10 +1,10 @@
|
||||||
<?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 @@ public static function query($class)
|
||||||
|
|
||||||
// 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 @@ public function save()
|
||||||
|
|
||||||
// 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 @@ public function delete($id = null)
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?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 @@ public function sweep($expiration)
|
||||||
*/
|
*/
|
||||||
private function table()
|
private function table()
|
||||||
{
|
{
|
||||||
return Manager::connection()->table(Config::get('session.table'));
|
return \System\DB::connection()->table(Config::get('session.table'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -302,7 +302,7 @@ protected function validate_unique($attribute, $parameters)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue