aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/CinIsis.php44
1 files changed, 30 insertions, 14 deletions
diff --git a/classes/CinIsis.php b/classes/CinIsis.php
index 77804c4..c38b70f 100644
--- a/classes/CinIsis.php
+++ b/classes/CinIsis.php
@@ -19,25 +19,41 @@ class CinIsis {
/**
* Constructor.
*
- * @param $config
- * Alternative config file (defaults to 'config/config.yaml').
- *
- * @todo
- * Config check.
+ * @param $file
+ * Optional parameter to set alternative config file.
*/
- function __construct($config = NULL) {
- if ($config == NULL) {
- $config = 'config/config.yaml';
- }
-
- // Load configuration.
- $config = Spyc::YAMLLoad($config);
+ function __construct($file = 'config/config.yaml') {
+ try {
+ // Load main configuration.
+ $config = $this->config($file);
- // Load database schema.
- $schema = Spyc::YAMLLoad('schemas/'. $config['database'] .'.yaml');
+ // Load database schema.
+ $schema = $this->config('schemas/'. $config['database'] .'.yaml');
+ } catch (Exception $e) {
+ echo '[cinisis] caught exception: ', $e->getMessage(), "\n";
+ return FALSE;
+ }
// Setup database connection.
$this->implementation = $config['implementation'] .'Db';
$this->db = new $this->implementation($schema);
}
+
+ /**
+ * Config file load.
+ *
+ * @param $file
+ * Config file.
+ *
+ * @return
+ * Array with configuration.
+ */
+ function config($file) {
+ if (!file_exists($file)) {
+ throw new Exception('Config '. $file .' not found.');
+ }
+
+ // Load configuration.
+ return Spyc::YAMLLoad($file);
+ }
}