Re: Re: Discussion of method -- config files

From: Date: Fri, 20 Jun 2008 18:45:35 +0000
Subject: Re: Re: Discussion of method -- config files
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-275728@lists.php.net to get a copy of this message
$reqdApplicFilesArray is not a global array [as in $GLOBALS]; it's simply a convenient way to list the variables I want to be globally available. The simple foreach defines them. Robert Cummings wrote:
On Fri, 2008-06-20 at 11:32 -0400, Al wrote:
Not so Robert, here's how I typically handle such situations. $reqdApplicFilesArray = array(// *Required application files and define() value 'regAdminSettings.db' => 'ADMIN_SETTINGS_FILE', 'regMemberData.db' => 'MEMBER_DATA_FILE', 'emailCellSettings.db' => 'EMAIL_CELL_SETTINGS_FILE', ); foreach($reqdApplicFilesArray as $file => $defineContant) {define($defineContant, $file);}
So you double declare your configuration data? Once as a global array, and a second time as broken out constants? How do you loop over configuration data? For instance I define multiple aliases databases and perform a lookup into the database configuration via the key: $GLOBALS['interJinn']['databases'] = array (
    'db1' => array( /* config */ ),
    'db2' => array( /* config */ ),
    'db3' => array( /* config */ ),
    'db4' => array( /* config */ ),
); Then request it: $db = &$mDb->getConnection( 'db1' ); Which would lookup the db: if( isset( $GLOBALS['interJinn']['databases'][$dbKey] ) ) {
    $config = $GLOBALS['interJinn']['databases'][$dbKey];
} This is a gross oversimplification of what happens, but essentially a lookup occurs at some point. It seems with constants I'd have to do some fancy string concatenation and checking for defined constants via dynamically built strings since each database configuration would be broken out into a set of scalar constant. I never did like constants for configuration, I never saw what they brought to the table. I see their role for enumerating datatypes or naming constant values within code, but not for configuration of said code. Cheers, Rob.


« previous php.general (#275728) next »