refactoring the database layer.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?php namespace Laravel\Database\Connector;
|
||||
|
||||
use Laravel\Database\Connector;
|
||||
|
||||
class Callback extends Connector {
|
||||
|
||||
/**
|
||||
|
||||
28
laravel/database/connector/connector.php
Normal file
28
laravel/database/connector/connector.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php namespace Laravel\Database\Connector;
|
||||
|
||||
use PDO;
|
||||
|
||||
abstract class Connector {
|
||||
|
||||
/**
|
||||
* The PDO connection options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = array(
|
||||
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Establish a PDO database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
*/
|
||||
abstract public function connect($config);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php namespace Laravel\Database\Connector;
|
||||
|
||||
use Laravel\Database\Connector;
|
||||
use PDO;
|
||||
|
||||
class MySQL extends Connector {
|
||||
|
||||
@@ -24,7 +24,7 @@ class MySQL extends Connector {
|
||||
$dsn .= ';unix_socket='.$config['socket'];
|
||||
}
|
||||
|
||||
$connection = new \PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||
$connection = new PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||
|
||||
if (isset($config['charset']))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php namespace Laravel\Database\Connector;
|
||||
|
||||
use Laravel\Database\Connector;
|
||||
use PDO;
|
||||
|
||||
class Postgres extends Connector {
|
||||
|
||||
@@ -19,7 +19,7 @@ class Postgres extends Connector {
|
||||
$dsn .= ';port='.$config['port'];
|
||||
}
|
||||
|
||||
$connection = new \PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||
$connection = new PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||
|
||||
if (isset($config['charset']))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php namespace Laravel\Database\Connector;
|
||||
|
||||
use Laravel\Database\Connector;
|
||||
use PDO;
|
||||
|
||||
class SQLite extends Connector {
|
||||
|
||||
@@ -14,15 +14,15 @@ class SQLite extends Connector {
|
||||
{
|
||||
if ($config['database'] == ':memory:')
|
||||
{
|
||||
return new \PDO('sqlite::memory:', null, null, $this->options);
|
||||
return new PDO('sqlite::memory:', null, null, $this->options);
|
||||
}
|
||||
elseif (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
|
||||
{
|
||||
return new \PDO('sqlite:'.$path, null, null, $this->options);
|
||||
return new PDO('sqlite:'.$path, null, null, $this->options);
|
||||
}
|
||||
elseif (file_exists($config['database']))
|
||||
{
|
||||
return new \PDO('sqlite:'.$config['database'], null, null, $this->options);
|
||||
return new PDO('sqlite:'.$config['database'], null, null, $this->options);
|
||||
}
|
||||
|
||||
throw new \Exception("SQLite database [".$config['database']."] could not be found.");
|
||||
|
||||
Reference in New Issue
Block a user