Sphido / Config
Sphido config loading configurations as pure PHP arrays/objects it's doing only array_replace_recursive!, (*1)
- no obscure config file parsers
- no extra config file formats
- no unnecessary code
- no power loss
Setup values
It's simple, just call config() in your index.php to setup values, (*2)
/app/config(
[],
include __DIR__ . '/config.base.php',
include __DIR__ . '/config.stable.php'
);
Your config.base.php need return some array values e.g.:, (*3)
return [
'example' => 'value',
'invokeme' => function() {}
'constant' => PHP_VERSION,
'execute' => $a + $b
'object' => (object)['a' => 'b', 'c' => 'd']
'array' => ['a' => 'b', 'c' => 'd']
];
Read and Write
Then simply read and write any values:, (*4)
/app/config()->example = 'save'
echo /app/config()->example; // will print save
It's pure PHP you can store whatever you need:, (*5)
/app/config()->invokeme = function() { return 'something'};
call_user_func(config()->invokeme);
Reinit config values
Sometimes you can need change whole config content in runtime, (*6)
/app/config(); // you can init empty config
/app/config(['oldConfigValues' => 'This is old content']);
/app/config(['reinitValues' => 'Reinit again...']);
/app/config()->reinitValues;