0 follower

Final Class Yiisoft\Config\Config

InheritanceYiisoft\Config\Config
ImplementsYiisoft\Config\ConfigInterface

Config takes merge plan prepared by {@see \Yiisoft\Config\Composer\EventHandler} and executes actual merge for the config group specified.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Config\Config
get() Returns the configuration of the group. Yiisoft\Config\Config
has() Yiisoft\Config\Config

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Config\ConfigPaths $paths, string|null $environment null, object[] $modifiers = [], string|null $paramsGroup 'params', string $mergePlanFile Options::DEFAULT_MERGE_PLAN_FILE )
$paths Yiisoft\Config\ConfigPaths

The config paths instance.

$environment string|null

The environment name.

$modifiers object[]

Modifiers that affect merge process.

$paramsGroup string|null

Group name for $params. If it is null, then $params will be empty array.

$mergePlanFile string

The merge plan filepath.

throws ErrorException

If the environment does not exist.

                public function __construct(
    ConfigPaths $paths,
    ?string $environment = null,
    array $modifiers = [],
    private readonly ?string $paramsGroup = 'params',
    string $mergePlanFile = Options::DEFAULT_MERGE_PLAN_FILE,
) {
    $environment = empty($environment) ? Options::DEFAULT_ENVIRONMENT : $environment;
    /** @psalm-suppress UnresolvableInclude, MixedArgument */
    $mergePlan = new MergePlan(require $paths->absolute($mergePlanFile));
    if (!$mergePlan->hasEnvironment($environment)) {
        $this->throwException(sprintf('The "%s" configuration environment does not exist.', $environment));
    }
    $dataModifiers = new DataModifiers($modifiers);
    $this->merger = new Merger($paths, $dataModifiers);
    $this->filesExtractor = new FilesExtractor($paths, $mergePlan, $dataModifiers, $environment);
}

            
get() public method

Returns the configuration of the group.

public array get ( string $group )
$group string

The configuration group name.

return array

The configuration of the group.

throws ErrorException

If the group does not exist or an error occurred during the build.

                public function get(string $group): array
{
    if (isset($this->build[$group])) {
        return $this->build[$group];
    }
    $this->runBuildParams();
    $this->merger->reset();
    $this->build[$group] = $this->buildGroup($group);
    return $this->build[$group];
}

            
has() public method

public boolean has ( string $group )
$group string

                public function has(string $group): bool
{
    return $this->filesExtractor->hasGroup($group);
}