Augmentation vers version 3.3.0
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
|
||||
/**
|
||||
@@ -19,53 +20,68 @@ use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class ResolveParameterPlaceHoldersPass implements CompilerPassInterface
|
||||
class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
|
||||
{
|
||||
private $bag;
|
||||
private $resolveArrays;
|
||||
|
||||
public function __construct($resolveArrays = true)
|
||||
{
|
||||
$this->resolveArrays = $resolveArrays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the ContainerBuilder to resolve parameter placeholders.
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws ParameterNotFoundException
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$parameterBag = $container->getParameterBag();
|
||||
$this->bag = $container->getParameterBag();
|
||||
|
||||
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()));
|
||||
if ($definition->getFactoryClass(false)) {
|
||||
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass(false)));
|
||||
}
|
||||
try {
|
||||
parent::process($container);
|
||||
|
||||
$factory = $definition->getFactory();
|
||||
$aliases = [];
|
||||
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);
|
||||
|
||||
if (\is_array($factory) && isset($factory[0])) {
|
||||
$factory[0] = $parameterBag->resolveValue($factory[0]);
|
||||
$definition->setFactory($factory);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$calls = array();
|
||||
foreach ($definition->getMethodCalls() as $name => $arguments) {
|
||||
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
|
||||
}
|
||||
$definition->setMethodCalls($calls);
|
||||
$this->bag->resolve();
|
||||
$this->bag = null;
|
||||
}
|
||||
|
||||
$definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
|
||||
} catch (ParameterNotFoundException $e) {
|
||||
$e->setSourceId($id);
|
||||
protected function processValue($value, $isRoot = false)
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
$v = $this->bag->resolveValue($value);
|
||||
|
||||
throw $e;
|
||||
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
|
||||
}
|
||||
if ($value instanceof Definition) {
|
||||
$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()));
|
||||
}
|
||||
}
|
||||
|
||||
$aliases = array();
|
||||
foreach ($container->getAliases() as $name => $target) {
|
||||
$aliases[$parameterBag->resolveValue($name)] = $target;
|
||||
}
|
||||
$container->setAliases($aliases);
|
||||
$value = parent::processValue($value, $isRoot);
|
||||
|
||||
$parameterBag->resolve();
|
||||
if ($value && \is_array($value)) {
|
||||
$value = array_combine($this->bag->resolveValue(array_keys($value)), $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user