0 follower

Final Class Yiisoft\Config\DataModifiers

InheritanceYiisoft\Config\DataModifiers

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( object[] $modifiers = [] )
$modifiers object[]

Modifiers that affect merge process.

                public function __construct(array $modifiers = [])
{
    $reverseMergeGroups = [];
    $recursiveMergeGroups = [];
    foreach ($modifiers as $modifier) {
        if ($modifier instanceof ReverseMerge) {
            array_unshift($reverseMergeGroups, $modifier->getGroups());
            continue;
        }
        if ($modifier instanceof RecursiveMerge) {
            array_unshift(
                $recursiveMergeGroups,
                array_fill_keys($modifier->getGroups(), $modifier->getDepth())
            );
            continue;
        }
        if ($modifier instanceof RemoveGroupsFromVendor) {
            foreach ($modifier->getGroups() as $package => $groups) {
                foreach ($groups as $group) {
                    $this->removeFromVendorGroupsIndex[$package . '~' . $group] = true;
                }
            }
            continue;
        }
        if ($modifier instanceof RemoveKeysFromVendor) {
            $configPaths = [];
            if ($modifier->getPackages() === []) {
                $configPaths[] = '*';
            } else {
                foreach ($modifier->getPackages() as $configPath) {
                    $package = array_shift($configPath);
                    if ($configPath === []) {
                        $configPaths[] = $package . '~*';
                    } else {
                        foreach ($configPath as $group) {
                            $configPaths[] = $package . '~' . $group;
                        }
                    }
                }
            }
            foreach ($modifier->getKeys() as $keyPath) {
                foreach ($configPaths as $configPath) {
                    $this->removeFromVendorKeysIndex[$configPath] ??= [];
                    ArrayHelper::setValue($this->removeFromVendorKeysIndex[$configPath], $keyPath, true);
                }
            }
        }
    }
    $this->reverseMergeGroupsIndex = array_flip(array_merge(...$reverseMergeGroups));
    $this->mergedGroupsRecursionDepthMap = array_merge(...$recursiveMergeGroups);
}

            
getRecursionDepth() public method

public false|integer|null getRecursionDepth ( string $group )
$group string
return false|integer|null
  • int - depth limited by specified number.
  • null - depth is not limited (infinite recursion).
  • false - recursion is disabled.

                public function getRecursionDepth(string $group): int|null|false
{
    if (!array_key_exists($group, $this->mergedGroupsRecursionDepthMap)) {
        return false;
    }
    return $this->mergedGroupsRecursionDepthMap[$group];
}

            
isReverseMergeGroup() public method

public boolean isReverseMergeGroup ( string $group )
$group string

                public function isReverseMergeGroup(string $group): bool
{
    return array_key_exists($group, $this->reverseMergeGroupsIndex);
}

            
shouldRemoveGroupFromVendor() public method

public boolean shouldRemoveGroupFromVendor ( string $package, string $group, integer $layer )
$package string
$group string
$layer integer

                public function shouldRemoveGroupFromVendor(string $package, string $group, int $layer): bool
{
    if ($layer !== Context::VENDOR) {
        return false;
    }
    return array_key_exists('*~*', $this->removeFromVendorGroupsIndex)
        || array_key_exists('*~' . $group, $this->removeFromVendorGroupsIndex)
        || array_key_exists($package . '~*', $this->removeFromVendorGroupsIndex)
        || array_key_exists($package . '~' . $group, $this->removeFromVendorGroupsIndex);
}

            
shouldRemoveKeyFromVendor() public method

public boolean shouldRemoveKeyFromVendor ( Yiisoft\Config\Context $context, array $keyPath )
$context Yiisoft\Config\Context
$keyPath array

                public function shouldRemoveKeyFromVendor(Context $context, array $keyPath): bool
{
    if ($context->layer() !== Context::VENDOR) {
        return false;
    }
    $configPaths = [
        '*',
        $context->package() . '~*',
        $context->package() . '~' . $context->group(),
    ];
    foreach ($configPaths as $configPath) {
        if (ArrayHelper::getValue($this->removeFromVendorKeysIndex[$configPath] ?? [], $keyPath) === true) {
            return true;
        }
    }
    return false;
}