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

88 lines
2.5 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
2010-12-29 19:12:24 +00:00
{
private $bag;
private $resolveArrays;
public function __construct($resolveArrays = true)
{
$this->resolveArrays = $resolveArrays;
}
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)] = $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)) {
$v = $this->bag->resolveValue($value);
return $this->resolveArrays || !$v || !is_array($v) ? $v : $value;
2010-12-29 19:12:24 +00:00
}
if ($value instanceof Definition) {
2017-11-07 08:01:11 +00:00
$value->setBindings($this->processValue($value->getBindings()));
$changes = $value->getChanges();
if (isset($changes['class'])) {
$value->setClass($this->bag->resolveValue($value->getClass()));
}
if (isset($changes['file'])) {
$value->setFile($this->bag->resolveValue($value->getFile()));
}
2010-12-29 19:12:24 +00:00
}
$value = parent::processValue($value, $isRoot);
if ($value && is_array($value)) {
$value = array_combine($this->bag->resolveValue(array_keys($value)), $value);
}
return $value;
2010-12-29 19:12:24 +00:00
}
}