From: Demian K. <dem...@vi...> - 2009-11-20 18:16:37
|
This seems like a reasonable addition... though the file_exists() check will add a tiny amount of file-access overhead on every page. Would it make sense to add a "local_overrides" setting to the [Extra_Config] section of config.ini, and only load in the local overrides if that setting exists? I realize this is a bit of a chicken and egg problem... but the config.ini setting would make it easier to skip the unwanted file_exists check if it is unnecessary, and it would also be a way of documenting the feature -- if there's a setting that activates it, people are more likely to realize they have the option of taking advantage of it. - Demian > -----Original Message----- > From: Tuan Nguyen [mailto:tu...@yo...] > Sent: Friday, November 20, 2009 12:25 PM > To: vuf...@li... > Subject: [VuFind-Tech] please comment: patch for configuration file > parsing > > Maybe this is useful and we can add this to the trunk so I don't have > to apply this patch each time we get a new release. We have about 3 > instances of VuFind (dev, test, production). Each only have 1 or 2 > differences in config.ini. So I added a couple of helper functions in > ConfigArray.php to override config.ini with values from > config.local.ini if the file exists. This way, if I only have a small > number of modification in config.ini. > > > Index: index.php > =================================================================== > --- index.php (revision 1857) > +++ index.php (working copy) > @@ -21,7 +21,8 @@ > /** CORE APPLICATION CONTOLLER **/ > > // Retrieve values from configuration file > -$configArray = parse_ini_file('conf/config.ini', true); > +require_once 'sys/ConfigArray.php'; > +$configArray = readConfig(); > setlocale(LC_MONETARY, $configArray['Site']['locale']); > date_default_timezone_set($configArray['Site']['timezone']); > > Index: index.php > =================================================================== > --- index.php (revision 1857) > +++ index.php (working copy) > @@ -21,7 +21,8 @@ > /** CORE APPLICATION CONTOLLER **/ > > // Retrieve values from configuration file > -$configArray = parse_ini_file('conf/config.ini', true); > +require_once 'sys/ConfigArray.php'; > +$configArray = readConfig(); > setlocale(LC_MONETARY, $configArray['Site']['locale']); > date_default_timezone_set($configArray['Site']['timezone']); > > Index: sys/ConfigArray.php > =================================================================== > --- sys/ConfigArray.php (revision 1857) > +++ sys/ConfigArray.php (working copy) > @@ -44,4 +44,24 @@ > > return $extraConfigs[$name]; > } > + > +function ini_merge($config_ini, $custom_ini) { > + foreach ($custom_ini as $k => $v) { > + if (is_array($v)) { > + $config_ini[$k] = ini_merge($config_ini[$k], > $custom_ini[$k]); > + } else { > + $config_ini[$k] = $v; > + } > + } > + return $config_ini; > +} > + > +function readConfig() { > + $mainArray = parse_ini_file('conf/config.ini', true); > + if (file_exists('conf/config.local.ini')) { > + $localOverride = parse_ini_file('conf/config.local.ini', > true); > + return ini_merge($mainArray, $localOverride); > + } > + return $mainArray; > +} > ?> > > > ----------------------------------------------------------------------- > ------- > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Vufind-tech mailing list > Vuf...@li... > https://lists.sourceforge.net/lists/listinfo/vufind-tech |