PHP Classes
PHP Classes
elePHPant
Icontem

Use configurations in a project - Fuse Array package blog

Recommend this page to a friend!
  All package blogs All package blogs   Fuse Array Fuse Array   Blog Fuse Array package blog   RSS 1.0 feed RSS 2.0 feed   Blog Use configurations in...  
  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Updated on: 2014-08-01

Posted on:

Package: Fuse Array

By using Fuse Array it gets much easier to handle configurations in a project.


 



One of the more compilcated problems to solve in a project is how to handle the configuration. Either you can define a whole bunch of constants or you can create an array with the settings you wish to use.
The problem with constants is that they can't be changed. On the other hand, an array with values can be changed.
But sometimes you might want some parts of the configuration to be read-only and some parts changable.
By using Fuse Array this becomes possible.

Let's look at a simple example.

Configuration file (config.ini)
[database]
host=localhost
type=pdo
username=user
password=pass

[paths]
public=/var/www/public
system=/var/www/system
Code
include('./extends/configarray.php');
$GLOBALS['config'] = ConfigArray::ConvertIni('/config.ini');
$GLOBALS['config']->Set('paths.cache', '/var/www/cache');
...
...
Later on in the code you may use $GLOBALS['config']->Get('desired key') to get a value from the configuration.
The values from the file config.ini is read-only, while the key "paths.cache" may be changed.

This solves some of the problems when you need to handle values defined in an external configuration file.

I hope that you can find this as useful as I did.



You need to be a registered user or login to post a comment

1,532,623 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

No comments were submitted yet.




  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  
  All package blogs All package blogs   Fuse Array Fuse Array   Blog Fuse Array package blog   RSS 1.0 feed RSS 2.0 feed   Blog Use configurations in...