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;
|
2017-01-17 20:04:53 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Definition;
|
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>
|
|
|
|
*/
|
2017-01-31 12:10:56 +00:00
|
|
|
class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
|
2010-12-29 19:12:24 +00:00
|
|
|
{
|
2017-01-17 20:04:53 +00:00
|
|
|
private $bag;
|
2017-06-12 12:31:43 +01:00
|
|
|
private $resolveArrays;
|
|
|
|
|
2017-10-28 19:15:32 +01:00
|
|
|
public function __construct(bool $resolveArrays = true)
|
2017-06-12 12:31:43 +01:00
|
|
|
{
|
|
|
|
$this->resolveArrays = $resolveArrays;
|
|
|
|
}
|
2017-01-17 20:04:53 +00:00
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
2017-01-17 20:04:53 +00:00
|
|
|
* {@inheritdoc}
|
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)
|
|
|
|
{
|
2017-01-17 20:04:53 +00:00
|
|
|
$this->bag = $container->getParameterBag();
|
2010-12-29 19:12:24 +00:00
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
try {
|
|
|
|
parent::process($container);
|
2015-03-14 11:13:05 +00:00
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
$aliases = array();
|
|
|
|
foreach ($container->getAliases() as $name => $target) {
|
|
|
|
$this->currentId = $name;
|
2017-10-02 07:42:24 +01:00
|
|
|
$aliases[$this->bag->resolveValue($name)] = $target;
|
2017-01-17 20:04:53 +00:00
|
|
|
}
|
|
|
|
$container->setAliases($aliases);
|
|
|
|
} catch (ParameterNotFoundException $e) {
|
|
|
|
$e->setSourceId($this->currentId);
|
2015-03-14 11:13:05 +00:00
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
2011-04-26 11:31:40 +01:00
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
$this->bag->resolve();
|
|
|
|
$this->bag = null;
|
|
|
|
}
|
2011-03-04 14:26:00 +00:00
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
protected function processValue($value, $isRoot = false)
|
|
|
|
{
|
2018-07-26 09:45:46 +01:00
|
|
|
if (\is_string($value)) {
|
2017-06-12 12:31:43 +01:00
|
|
|
$v = $this->bag->resolveValue($value);
|
|
|
|
|
2018-07-26 09:45:46 +01:00
|
|
|
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
2017-01-17 20:04:53 +00:00
|
|
|
if ($value instanceof Definition) {
|
2017-11-07 08:01:11 +00:00
|
|
|
$value->setBindings($this->processValue($value->getBindings()));
|
2017-04-05 13:12:51 +01:00
|
|
|
$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
|
|
|
}
|
2011-05-26 07:26:14 +01:00
|
|
|
|
2017-06-12 10:39:35 +01:00
|
|
|
$value = parent::processValue($value, $isRoot);
|
|
|
|
|
2018-07-26 09:45:46 +01:00
|
|
|
if ($value && \is_array($value)) {
|
2017-06-12 10:39:35 +01:00
|
|
|
$value = array_combine($this->bag->resolveValue(array_keys($value)), $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
2010-12-30 16:27:43 +00:00
|
|
|
}
|