consolidation/config
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
dflydev/dot-access-data | v3.0.2 | 10.25 kB | MIT | prod | |
grasmash/expander | 3.0.0 | 25.62 kB | MIT | prod | |
symfony/event-dispatcher | v6.4.7 | - | MIT | prod |
Consolidation/Config is a component designed to provide configuration services for a console command line tool. The package enables management of configuration options from different sources including command line options, configuration files, alias files (which specifically identify a target site), and default values that are provided by the command. It makes use of Symfony Console for the command line tool's framework and the Symfony Configuration component to load and merge configuration files.
To use consolidation/config, you will need to first introduce it into your project. The primary object for configuration import and export is theConfig object. Here's how to do it:
use Consolidation\Config\Config;
use Consolidation\Config\YamlConfigLoader;
use Consolidation\Config\ConfigProcessor;
$config = new Config();
$loader = new YamlConfigLoader();
$processor = new ConfigProcessor();
$processor->extend($loader->load('defaults.yml'));
$processor->extend($loader->load('myconf.yml'));
$config->import($processor->export());
You can also set-up command option configuration injection like this:
$application = new Symfony\Component\Console\Application($name, $version);
$configInjector = new \Consolidation\Config\Inject\ConfigForCommand($config);
$configInjector->setApplication($application);
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addSubscriber($configInjector);
$application->setDispatcher($eventDispatcher);
Configuration values can be easily fetched as follows:
$value = $config->get('a.b.c');
And you may perform interpolation like this:
$result = $config->interpolate('The value is: {{a.b.c}}');
Consolidation/Config’s documentation is located on GitHub, specifically the repository README file at the given URL: https://github.com/consolidation/config. This resource explains detailed usage, code examples, and additional functionalities of the package and even offers comparisons to similar utilities.