aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-04-05 11:41:38 -0300
committerSilvio <silvio@devlet.com.br>2010-04-05 11:41:38 -0300
commitf3ba92efd81b5ada2690b5d4b9708c2e390abf89 (patch)
treec6aaba23084ad796473f33fc839c47699bbf4f52 /classes
parent216b933be24ae428a96c8b3d3b3d702b4211d2d6 (diff)
downloadcinisis-f3ba92efd81b5ada2690b5d4b9708c2e390abf89.tar.gz
cinisis-f3ba92efd81b5ada2690b5d4b9708c2e390abf89.tar.bz2
Config file loading
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);
+ }
}