This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

63 lines
2.1 KiB
PHP
Raw Normal View History

2010-12-29 19:12:24 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-12-29 19:12:24 +00:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-12-29 19:12:24 +00:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-12-29 19:12:24 +00:00
*/
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
2010-12-29 19:12:24 +00:00
/**
* Resolves all parameter placeholders "%somevalue%" to their real values.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ResolveParameterPlaceHoldersPass implements CompilerPassInterface
{
private $parameterBag;
2010-12-29 19:12:24 +00:00
2011-02-13 18:06:41 +00:00
/**
* Processes the ContainerBuilder to resolve parameter placeholders.
*
* @param ContainerBuilder $container
2011-02-13 18:06:41 +00:00
*/
2010-12-29 19:12:24 +00:00
public function process(ContainerBuilder $container)
{
$parameterBag = $container->getParameterBag();
$parameterBag->resolve();
2010-12-29 19:12:24 +00:00
foreach ($container->getDefinitions() as $id => $definition) {
try {
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
2010-12-29 19:12:24 +00:00
$calls = array();
foreach ($definition->getMethodCalls() as $name => $arguments) {
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
}
$definition->setMethodCalls($calls);
$definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
} catch (ParameterNotFoundException $e) {
$e->setSourceId($id);
throw $e;
}
2010-12-29 19:12:24 +00:00
}
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
2010-12-29 19:12:24 +00:00
}
$container->setAliases($aliases);
}
}