Skip to content

Commit

Permalink
improving config initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Jul 7, 2013
1 parent 20dfe42 commit 83204c9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ function __construct($id=0, $table='sqlite_master') {
}

static function register($table, $key, $value="") {
// create the global config object if not available
if(!array_key_exists('config', $GLOBALS)) $GLOBALS['config'] = array();
// exit now if variable already available
$key_exists = !( empty($GLOBALS['config'][$table][$key]) && is_null($GLOBALS['config'][$table][$key]) );
$key_exists = !( !array_key_exists($table, $GLOBALS['config']) || (empty($GLOBALS['config'][$table][$key]) && is_null($GLOBALS['config'][$table][$key])));
if ( $key_exists ) return;

// then check if the table exists
Expand Down Expand Up @@ -45,6 +47,8 @@ function getConfig(){
if( !is_array( $table_rows ) ){ return false; }
// clean up data in a better format
foreach( $table_rows as $table => $rows ){
// create the config table if it doesn't exist
if( !array_key_exists($table, $config) ) $config[$table] = array();
foreach( $rows as $row ){
// delete a duplicate key
if( array_key_exists( $row['key'], $config[$table] ) ){
Expand Down

0 comments on commit 83204c9

Please sign in to comment.