refactoring the database layer.

This commit is contained in:
Taylor Otwell
2011-09-11 23:25:31 -05:00
parent 3ada2cbd3e
commit 2521ab3c1d
12 changed files with 19 additions and 25 deletions

View File

@@ -1,7 +1,5 @@
<?php namespace Laravel\Database\Connector;
use Laravel\Database\Connector;
class Callback extends Connector {
/**

View 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);
}

View File

@@ -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']))
{

View File

@@ -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']))
{

View File

@@ -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.");