2010-12-29 19:12:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +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
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-05-17 15:26:08 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
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
|
|
|
|
{
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Processes the ContainerBuilder to resolve parameter placeholders.
|
|
|
|
*
|
2011-03-04 14:26:00 +00:00
|
|
|
* @param ContainerBuilder $container
|
2012-09-07 23:56:45 +01:00
|
|
|
*
|
2012-12-16 12:02:54 +00:00
|
|
|
* @throws ParameterNotFoundException
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
2011-05-25 08:06:09 +01:00
|
|
|
$parameterBag = $container->getParameterBag();
|
2010-12-29 19:12:24 +00:00
|
|
|
|
2011-04-26 11:31:40 +01:00
|
|
|
foreach ($container->getDefinitions() as $id => $definition) {
|
|
|
|
try {
|
2011-05-25 08:06:09 +01:00
|
|
|
$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
|
|
|
|
2011-04-26 11:31:40 +01:00
|
|
|
$calls = array();
|
|
|
|
foreach ($definition->getMethodCalls() as $name => $arguments) {
|
2011-05-25 08:06:09 +01:00
|
|
|
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
|
2011-04-26 11:31:40 +01:00
|
|
|
}
|
|
|
|
$definition->setMethodCalls($calls);
|
|
|
|
|
2011-05-25 08:06:09 +01:00
|
|
|
$definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
|
2011-05-17 15:26:08 +01:00
|
|
|
} catch (ParameterNotFoundException $e) {
|
2011-04-26 11:31:40 +01:00
|
|
|
$e->setSourceId($id);
|
2011-03-04 14:26:00 +00:00
|
|
|
|
2011-04-26 11:31:40 +01:00
|
|
|
throw $e;
|
|
|
|
}
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$aliases = array();
|
|
|
|
foreach ($container->getAliases() as $name => $target) {
|
2011-05-25 08:06:09 +01:00
|
|
|
$aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
$container->setAliases($aliases);
|
2011-05-26 07:26:14 +01:00
|
|
|
|
|
|
|
$parameterBag->resolve();
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
2010-12-30 16:27:43 +00:00
|
|
|
}
|