symplify/set-config-resolver

This package is abandoned and no longer maintained. No replacement package was suggested.

Resolve config and sets from configs and cli opptions for CLI applications

v9.3.12 2021-05-17 20:55 UTC

This package is auto-updated.

Last update: 2021-05-17 20:58:05 UTC


README

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.