Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / ResolveParameterPlaceHoldersPass.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Compiler;
13
14 use Symfony\Component\DependencyInjection\ContainerBuilder;
15 use Symfony\Component\DependencyInjection\Definition;
16 use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
17
18 /**
19  * Resolves all parameter placeholders "%somevalue%" to their real values.
20  *
21  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
22  */
23 class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
24 {
25     private $bag;
26     private $resolveArrays;
27
28     public function __construct($resolveArrays = true)
29     {
30         $this->resolveArrays = $resolveArrays;
31     }
32
33     /**
34      * {@inheritdoc}
35      *
36      * @throws ParameterNotFoundException
37      */
38     public function process(ContainerBuilder $container)
39     {
40         $this->bag = $container->getParameterBag();
41
42         try {
43             parent::process($container);
44
45             $aliases = array();
46             foreach ($container->getAliases() as $name => $target) {
47                 $this->currentId = $name;
48                 $aliases[$this->bag->resolveValue($name)] = $target;
49             }
50             $container->setAliases($aliases);
51         } catch (ParameterNotFoundException $e) {
52             $e->setSourceId($this->currentId);
53
54             throw $e;
55         }
56
57         $this->bag->resolve();
58         $this->bag = null;
59     }
60
61     protected function processValue($value, $isRoot = false)
62     {
63         if (\is_string($value)) {
64             $v = $this->bag->resolveValue($value);
65
66             return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
67         }
68         if ($value instanceof Definition) {
69             $value->setBindings($this->processValue($value->getBindings()));
70             $changes = $value->getChanges();
71             if (isset($changes['class'])) {
72                 $value->setClass($this->bag->resolveValue($value->getClass()));
73             }
74             if (isset($changes['file'])) {
75                 $value->setFile($this->bag->resolveValue($value->getFile()));
76             }
77         }
78
79         $value = parent::processValue($value, $isRoot);
80
81         if ($value && \is_array($value)) {
82             $value = array_combine($this->bag->resolveValue(array_keys($value)), $value);
83         }
84
85         return $value;
86     }
87 }