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

70 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\Definition;
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 extends AbstractRecursivePass implements CompilerPassInterface
2010-12-29 19:12:24 +00:00
{
private $bag;
2011-02-13 18:06:41 +00:00
/**
* {@inheritdoc}
*
* @throws ParameterNotFoundException
2011-02-13 18:06:41 +00:00
*/
2010-12-29 19:12:24 +00:00
public function process(ContainerBuilder $container)
{
$this->bag = $container->getParameterBag();
2010-12-29 19:12:24 +00:00
try {
parent::process($container);
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$this->currentId = $name;
$aliases[$this->bag->resolveValue($name)] = $this->bag->resolveValue($target);
}
$container->setAliases($aliases);
} catch (ParameterNotFoundException $e) {
$e->setSourceId($this->currentId);
throw $e;
}
$this->bag->resolve();
$this->bag = null;
}
protected function processValue($value, $isRoot = false)
{
if (is_string($value)) {
return $this->bag->resolveValue($value);
2010-12-29 19:12:24 +00:00
}
if ($value instanceof Definition) {
$value->setClass($this->bag->resolveValue($value->getClass()));
$value->setFile($this->bag->resolveValue($value->getFile()));
$value->setProperties($this->bag->resolveValue($value->getProperties()));
$value->setMethodCalls($this->bag->resolveValue($value->getMethodCalls()));
2010-12-29 19:12:24 +00:00
}
return parent::processValue($value, $isRoot);
2010-12-29 19:12:24 +00:00
}
}