Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag::mergeEnvPlaceholders PHP Method

mergeEnvPlaceholders() public method

Merges the env placeholders of another EnvPlaceholderParameterBag.
public mergeEnvPlaceholders ( self $bag )
$bag self
    public function mergeEnvPlaceholders(self $bag)
    {
        if ($newPlaceholders = $bag->getEnvPlaceholders()) {
            $this->envPlaceholders += $newPlaceholders;
            foreach ($newPlaceholders as $env => $placeholders) {
                $this->envPlaceholders[$env] += $placeholders;
            }
        }
    }

Usage Example

コード例 #1
0
 public function testMergeWithDifferentIdentifiersForPlaceholders()
 {
     $envName = 'DB_USER';
     $paramName = sprintf('env(%s)', $envName);
     $firstBag = new EnvPlaceholderParameterBag();
     $secondBag = new EnvPlaceholderParameterBag();
     // initialize placeholders
     $firstPlaceholder = $firstBag->get($paramName);
     $secondPlaceholder = $secondBag->get($paramName);
     $firstBag->mergeEnvPlaceholders($secondBag);
     $merged = $firstBag->getEnvPlaceholders();
     $this->assertNotEquals($firstPlaceholder, $secondPlaceholder);
     $this->assertCount(2, $merged[$envName]);
 }