Load simple variables into the PHP global scope using an "ini" file.
This is meant to be quick for installation and usage.
Currently, the only variable types available for loading are: single-depth arrays (associative and numeric) and scalar.
Obviously, care should be taken when loading any variables into the global scope, if and when possible -- don't use globals! Please take care to not overwrite other global variables. You have been forewarned, and you will assume use of this code at your own risk.
This project is licensed under the terms of the MIT license. See the included "License.txt" for more information.
For the purpose of this demonstration, the ini file shall be called: '.gload.ini', but you can use a different file name, if you would like.
composer require brokerexchange/gloadals
require_once(<PATH_TO_VENDOR_DIRECTORY> . '/vendor/autoload.php' );
;simple (one level deep maximum)
associative_array1[associative_index1] = "test_value1"
associative_array1[associative_index2] = test_value2
numeric_array1[] = "test_value3"
scalar = test_value4
;multidimensional (when using ini - up to two levels deep *maximum* and must be placed after all simple variables)
[multidimensional]
levelone[leveltwo] = "testing"
levelone[another_leveltwo] = "testing testing"
levelone[yet_another_leveltwo] = "testing"
<?php
/* Can load associative arrays many-levels deep */
$associative_array = [
'a_name1' => 'a_value1',
'a_name2'=> 'a_value2',
'a_name3' => 'a_value3',
'a_name4' => [
'leveltwo' => [
'levelthree' => 'a_value4'
]
]
];
$numeric_array['n_name'] = ['value1','value2','value3'];
$scalar = [
's_name1' => 's_value1',
's_name2' => 's_value2',
's_name3' => 's_value3'
];
use BrokerExchange\Gloadals
.
.
.
//(a) ini
Gloadals::load( <PATH_TO_INI_FILE> . '/.gload.ini' );
//(b) php
Gloadals::load( <PATH_TO_FILE> . '/.gload.php', 'php');
print_r($GLOBALS);
(a) When loading via ini format:
.
.
.
[associative_array1] => Array
(
[associative_index1] => test_value1
[associative_index2] => test_value2
)
[numeric_array1] => Array
(
[0] => test_value3
)
[scalar] => test_value4
[multidimensional] => Array
(
[levelone] => Array
(
[leveltwo] => testing
[another_leveltwo] => testing testing
[yet_another_leveltwo] => testing
)
)
)
(b) When loading via php format:
[a_name1] => a_value1
[a_name2] => a_value2
[a_name3] => a_value3
[a_name4] => Array
(
[leveltwo] => Array
(
[levelthree] => a_value4
)
)
[n_name] => Array
(
[0] => Array
(
[0] => n_value1
[1] => n_value2
[2] => n_value3
)
)
[s_name1] => s_value1
[s_name2] => s_value2
[s_name3] => s_value3