[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Compiler/ -> ResolveParameterPlaceHoldersPass.php (source)

   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      private $throwOnResolveException;
  28  
  29      public function __construct($resolveArrays = true, $throwOnResolveException = true)
  30      {
  31          $this->resolveArrays = $resolveArrays;
  32          $this->throwOnResolveException = $throwOnResolveException;
  33      }
  34  
  35      /**
  36       * {@inheritdoc}
  37       *
  38       * @throws ParameterNotFoundException
  39       */
  40      public function process(ContainerBuilder $container)
  41      {
  42          $this->bag = $container->getParameterBag();
  43  
  44          try {
  45              parent::process($container);
  46  
  47              $aliases = [];
  48              foreach ($container->getAliases() as $name => $target) {
  49                  $this->currentId = $name;
  50                  $aliases[$this->bag->resolveValue($name)] = $target;
  51              }
  52              $container->setAliases($aliases);
  53          } catch (ParameterNotFoundException $e) {
  54              $e->setSourceId($this->currentId);
  55  
  56              throw $e;
  57          }
  58  
  59          $this->bag->resolve();
  60          $this->bag = null;
  61      }
  62  
  63      protected function processValue($value, $isRoot = false)
  64      {
  65          if (\is_string($value)) {
  66              try {
  67                  $v = $this->bag->resolveValue($value);
  68              } catch (ParameterNotFoundException $e) {
  69                  if ($this->throwOnResolveException) {
  70                      throw $e;
  71                  }
  72  
  73                  $v = null;
  74                  $this->container->getDefinition($this->currentId)->addError($e->getMessage());
  75              }
  76  
  77              return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
  78          }
  79          if ($value instanceof Definition) {
  80              $value->setBindings($this->processValue($value->getBindings()));
  81              $changes = $value->getChanges();
  82              if (isset($changes['class'])) {
  83                  $value->setClass($this->bag->resolveValue($value->getClass()));
  84              }
  85              if (isset($changes['file'])) {
  86                  $value->setFile($this->bag->resolveValue($value->getFile()));
  87              }
  88          }
  89  
  90          $value = parent::processValue($value, $isRoot);
  91  
  92          if ($value && \is_array($value)) {
  93              $value = array_combine($this->bag->resolveValue(array_keys($value)), $value);
  94          }
  95  
  96          return $value;
  97      }
  98  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1