refactor sqlite connector to accept path in constructor.

This commit is contained in:
Taylor Otwell 2011-10-20 22:17:40 -05:00
parent 23c79a0317
commit 21dccae755
2 changed files with 20 additions and 2 deletions

View File

@ -53,7 +53,7 @@
'laravel.database.connectors.sqlite' => array('resolver' => function($c)
{
return new Database\Connectors\SQLite;
return new Database\Connectors\SQLite(DATABASE_PATH);
}),
'laravel.database.connectors.mysql' => array('resolver' => function($c)

View File

@ -2,6 +2,24 @@
class SQLite extends Connector {
/**
* The path to the SQLite databases for the application.
*
* @var string
*/
protected $path;
/**
* Create a new SQLite database connector instance.
*
* @param string $path
* @return void
*/
public function __construct($path)
{
$this->path = $path;
}
/**
* Establish a PDO database connection for a given database configuration.
*
@ -21,7 +39,7 @@ public function connect($config)
// application. If we don't find the database there, we will assume the database
// name is actually a full qualified path to the database on disk and attempt
// to load it. If we still can't find it, we'll bail out.
elseif (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
elseif (file_exists($path = $this->path.$config['database'].'.sqlite'))
{
return new PDO('sqlite:'.$path, null, null, $options);
}