From 68b4e5533635fbafbcb62479c999172095dcf3e5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 17 Mar 2012 16:12:26 -0500 Subject: [PATCH] Cleaning up code. Signed-off-by: Taylor Otwell --- laravel/database/connectors/mysql.php | 3 +++ laravel/database/connectors/sqlite.php | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/laravel/database/connectors/mysql.php b/laravel/database/connectors/mysql.php index 568504e0..0ea5eba2 100644 --- a/laravel/database/connectors/mysql.php +++ b/laravel/database/connectors/mysql.php @@ -22,6 +22,9 @@ public function connect($config) $dsn .= ";port={$config['port']}"; } + // The UNIX socket option allows the developer to indicate that the MySQL + // instance must be connected to via a given socket. We'll just append + // it to the DSN connection string if it is present. if (isset($config['unix_socket'])) { $dsn .= ";unix_socket={$config['unix_socket']}"; diff --git a/laravel/database/connectors/sqlite.php b/laravel/database/connectors/sqlite.php index 8e7d70d2..e7867532 100644 --- a/laravel/database/connectors/sqlite.php +++ b/laravel/database/connectors/sqlite.php @@ -12,18 +12,29 @@ public function connect($config) { $options = $this->options($config); - // SQLite provides supported for "in-memory" databases, which exist only for the - // lifetime of the request. Any given in-memory database may only have one PDO - // connection open to it at a time. These are usually for testing. + // SQLite provides supported for "in-memory" databases, which exist only for + // lifetime of the request. Any given in-memory database may only have one + // PDO connection open to it at a time. These are mainly for tests. if ($config['database'] == ':memory:') { return new PDO('sqlite::memory:', null, null, $options); } - // SQLite databases will be created automatically if they do not exist, so we - // will not check for the existence of the database file before establishing - // the PDO connection to the database. - $path = path('storage').'database'.DS.$config['database'].'.sqlite'; + // We'll allow the "database" configuration option to be a fully qualified + // path to the database so we'll check if that is the case first. If it + // isn't a fully qualified path we will use the storage directory. + if (file_exists($config['database'])) + { + $path = $config['database']; + } + + // The database option does not appear to be a fully qualified path so we + // will just assume it is a relative path from the storage directory + // which is typically used to store all SQLite databases. + else + { + $path = path('storage').'database'.DS.$config['database'].'.sqlite'; + } return new PDO('sqlite:'.$path, null, null, $options); }