, (*1)
Configuration item supports laravel extension.
, (*2)
Simplified Chinese Documentation
, (*3)
Features
- Support component configuration, configuration files can be anywhere.
- Overlay configuration, flexible.
Environment
php >= 7.1
Laravel >= 5.1, (*4)
Installing
composer require ofcold/configuration
Instructions
We may use such a scenario, in the development of Laravel components, need some configuration, or multiple configuration items. The original Laravel may require you to merge configurations and publish to the root directory.
As the number of components increases, so does the config file., (*5)
Useing
use Ofcold\Configuration\LoaderConfiguration;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Config\Repository;
$loader = new LoaderConfiguration(
$config = new Repository,
new Filesystem
);
$loader->addNamespace('test', __DIR__ . '/tests/config');
print_r(json_encode($config->all()));
// print_r($config->get('test::test.foo') . "\r\n");
$loader->addNamespaceOverrides('test', __DIR__ . '/tests/overrides');
print_r(json_encode($config->all()));
// print_r($config->get('test::test.foo') . "\r\n");
Results:
{
"test::test":{
"foo":"example"
}
}
{
"test::test":{
"foo":"overrides"
}
}
Larvel, (*6)
use Ofcold\Configuration\LoaderConfiguration;
class Foo
{
/**
* Create an a new Foo instance.
*
* @param LoaderConfiguration $loader
*/
public function __construct(LoaderConfiguration $loader)
{
$loader->addNamespace('test', '/config');
}
}
OR test file.
php test
Api
- addNamespace(?string $namespace = null, string $directory) : void
- addNamespaceOverrides($namespace, $directory) : void