diff options
author | Silvio <silvio@devlet.com.br> | 2010-04-06 16:16:50 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-04-06 16:16:50 -0300 |
commit | a80a88d99cb102fad4a23d5ea5732d489e70eddf (patch) | |
tree | 8d5a4bb15b3d6d38ed8bc132dc507c56d23a1711 /classes/CinisisDb.php | |
parent | f6f1d270419bbd9696974719b15b8c01b19b032b (diff) | |
download | cinisis-a80a88d99cb102fad4a23d5ea5732d489e70eddf.tar.gz cinisis-a80a88d99cb102fad4a23d5ea5732d489e70eddf.tar.bz2 |
Enhanced config check
Diffstat (limited to 'classes/CinisisDb.php')
-rw-r--r-- | classes/CinisisDb.php | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/classes/CinisisDb.php b/classes/CinisisDb.php index ae80a00..3dead27 100644 --- a/classes/CinisisDb.php +++ b/classes/CinisisDb.php @@ -28,16 +28,18 @@ class CinisisDb { // Check main configuration. $config = $this->parse($config); + // Set database implementation. + $this->implementation = $config['implementation'] .'Db'; + // Check database schema. - $schema = $this->parse('schemas/'. $config['database'] .'.yaml', 'schema'); + $schema = $this->parse('schemas/'. $config['database'] .'.yaml', $this->implementation); } catch (Exception $e) { - echo '[cinisis] caught exception: ', $e->getMessage(), "\n"; + echo __CLASS__ .' caught exception: ', $e->getMessage(), "\n"; return FALSE; } // Setup database connection. - $this->implementation = $config['implementation'] .'Db'; - $this->db = new $this->implementation($schema); + $this->db = new $this->implementation($schema); } /** @@ -47,11 +49,12 @@ class CinisisDb { * Config file. * * @return - * Array with configuration. + * Array with configuration or FALSE if error. */ - function load($file) { + public function load($file) { if (!file_exists($file)) { throw new Exception('Config '. $file .' not found.'); + return FALSE; } // Load configuration. @@ -64,20 +67,19 @@ class CinisisDb { * @param $config * Config file or array with configuration. * - * @param $type - * Configuration type (either 'cinisis' or 'schema'). + * @param $class + * Configuration class name. * * @return * Array with configuration or FALSE on error. */ - function parse($config, $type = 'cinisis') { + public function parse($config, $class = __CLASS__) { // Load configuration if needed. if (!is_array($config)) { $config = $this->load($config); } // Check configuration. - $class = ucfirst($type) .'Db'; return call_user_func(array($class, 'check'), $config); } @@ -99,6 +101,7 @@ class CinisisDb { // Check database configuration. if (!isset($config['database'])) { throw new Exception('No database set on configuration.'); + return FALSE; } return $config; |