/set-config-resolver

[READ-ONLY] Loads configs to you with CLI --config, -c, --set, -s or sets parameter

Primary LanguagePHPMIT LicenseMIT

Set Config Resolver

Downloads total

Install

composer require symplify/set-config-resolver

Load a Config for CLI Application?

Use in CLI entry file bin/<app-name>, e.g. bin/ecs or bin/rector.

use Symfony\Component\Console\Input\ArgvInput;
use Symplify\EasyCodingStandard\Set\EasyCodingStandardSetProvider;
use Symplify\SetConfigResolver\SetAwareConfigResolver;

$configs = [];

// 1. --config CLI option or local fallback
$configResolver = new SetAwareConfigResolver(new EasyCodingStandardSetProvider(...));
$inputConfig = $configResolver->resolveFromInputWithFallback(new ArgvInput(), ['ecs.php']);

if ($inputConfig !== null) {
    $configs[] = $inputConfig;
}

// 2. "parameters > set" in provided PHP configs
$parameterSetsConfigs = $configResolver->resolveFromParameterSetsFromConfigFiles($configs);
if ($parameterSetsConfigs !== []) {
    $configs = array_merge($configs, $parameterSetsConfigs);
}

// Build DI container
$appKernel = new AppKernel('prod', true);
if ($configs !== []) {
    $appKernel->setConfigs($configs);
}

$appKernel->boot();

$container = $appKernel->getContainer();

And use like this:

vendor/bin/your-app --config config/set/the-config.yaml

...or...

vendor/bin/your-app --set the-config

...or with this config:

parameters:
    sets:
        - "the-config"

All are equal :)


Report Issues

In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker

Contribute

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify.