cgm225 Posted April 18, 2008 Share Posted April 18, 2008 Currently, I have a Registry class where I store default and/or general variables that are used in several classes (for example, a variable containing the root path address). I have included the class below which simply contains a (1) set function and (2) get function. However, I would like to add a (3) third function to import preset default values from another settings file, such that I can do a $registry->import('/app/settings.ini') type thing. Could someone help me do this? Regardless, thank you all for your help on these forums! <?php class Registry { private $store = array(); public function __set($label, $object) { if(!isset($this->store[$label])) { $this->store[$label] = $object; } } public function __get($label) { if(isset($this->store[$label])) { return $this->store[$label]; } return false; } } //Current example of usage $registry = new Registry(); $registry->__set("Database Name", "mysql.internal"); echo $registry->__get("Database Name"); //Outputs "mysql.internal" /* What I would like to add is some type of function that adds labels and objects from a settings file, so something like:: $registry->import('/app/settings.ini'); */ ?> Link to comment https://forums.phpfreaks.com/topic/101719-setting-up-a-default-array-in-settings-file-with-default-variable-values/ Share on other sites More sharing options...
cgm225 Posted April 18, 2008 Author Share Posted April 18, 2008 I am thinking in my import method I could use parse_ini_file and use the setter method on each array, but I am not exactly sure how to do that. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/101719-setting-up-a-default-array-in-settings-file-with-default-variable-values/#findComment-520487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.