I am trying to make a class that will load my .ini files for me. The rundown is that I specify the name of the application I'm working with, then give it a single or array of files for it to load for me. Once that is done I just call it like so.
Ini::path(BASE_PATH . "config" . DS);
Ini::set_app("testApp");
Ini::load(array("db", "web", "themer"));
then I'm trying to use it like this
echo Ini::$get['testApp']['someKey']['someValue'];
at the moment I can use it without the Ini::$app being set because I'm trying to add that features. i.e Ini::$get['someKey']['someValue'];
My problem is that I cannot figure out how to push more .ini files into the Ini::$get array. The usage should be something like this
Ini::push("anotherIni");
that is suppose to call my push method and push the new file into the array. But I can't seem to build the array correctly. Either that, or it is not possible to push a new value into a static array.
My array with the array_push attempt looks like this ounce outputted with a print_r()
Array ( [testApp] => )
otherwise it outputs this without me trying to push the new ini into the array
Array ( [testApp] => Array ( [db] => [web] => [themer] => ) )
Here is my Class file (Updated to reflect answers)
class Ini {
public static $get = array();
public static $tmp = array();
public static $path;
public static $app;
public static $push;
public static function load($file)
{
if (is_array($file)) {
foreach ($file as $ini)
self::$get[self::$app][$ini] = parse_ini_file(self::$path . $ini . ".ini", true);
//array_push(self::$get[self::$app], "testIni");
} else {
self::$get[self::$app][$file] = parse_ini_file(self::$path . $file . ".ini", true);
}
}
public static function push($file)
{
self::$tmp[$file] = parse_ini_file(self::$path . $file . ".ini", true);
array_push(self::$get[self::$app], self::$tmp[$file]);
}
public static function set_app($name)
{
self::$app = $name;
self::$get[self::$app] = array();
}
public static function path($path)
{
self::$path = $path;
return self::$path;
}
// TODO: Create 'write', 'delete', 'append' function to change ini values
}