From f3ba92efd81b5ada2690b5d4b9708c2e390abf89 Mon Sep 17 00:00:00 2001 From: Silvio Date: Mon, 5 Apr 2010 11:41:38 -0300 Subject: Config file loading --- classes/CinIsis.php | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'classes/CinIsis.php') 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); + } } -- cgit v1.2.3