From 7d732790d2d7cff4e051edc699a99ca35cbfa9d1 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 6 May 2015 18:26:19 +0200 Subject: [PATCH] Fix for issue #51. Tighter checks on input --- .gitignore | 7 ++++++- Modules/database/class.database.php | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8c35911..a8bf102 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,11 @@ FuzeWorks.esproj/* *.DS_Store *.swp *.out + +# Framework Files Core/Cache/ Core/Logs/Error.log -build/ + +# Build Files +vendor/ +build/ \ No newline at end of file diff --git a/Modules/database/class.database.php b/Modules/database/class.database.php index bdc5c9a..9275d27 100644 --- a/Modules/database/class.database.php +++ b/Modules/database/class.database.php @@ -3,6 +3,7 @@ namespace Module\Database; use \FuzeWorks\Module; use \PDO; +use \FuzeWorks\DatabaseException; class Main extends Module { @@ -22,6 +23,11 @@ class Main extends Module { $this->config->dbActive = true; } + /** + * Connect to a database + * @access public + * @param StdObject Config, like the database config in Application/Config + */ public function connect($config = null) { // If nothing is given, connect to database from the main config, otherwise use the served configuration if (is_null($config)) { @@ -29,6 +35,10 @@ class Main extends Module { } else { $db = $config; } + + if (empty($db->type) || empty($db->host)) { + throw (new DatabaseException('Database is not configured!')); + } // Get the DSN for popular types of databases or a custom DSN switch (strtolower($db->type)) { @@ -51,7 +61,7 @@ class Main extends Module { // And set the prefix $this->prefix = $db->prefix; } catch (Exception $e) { - throw (new Exception('Could not connect to the database: "'. $e->getMessage() . '"')); + throw (new DatabaseException('Could not connect to the database: "'. $e->getMessage() . '"')); } }