[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Compiler/ -> DecoratorServicePass.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\Alias;
  15  use Symfony\Component\DependencyInjection\ContainerBuilder;
  16  
  17  /**
  18   * Overwrites a service but keeps the overridden one.
  19   *
  20   * @author Christophe Coevoet <stof@notk.org>
  21   * @author Fabien Potencier <fabien@symfony.com>
  22   * @author Diego Saint Esteben <diego@saintesteben.me>
  23   */
  24  class DecoratorServicePass implements CompilerPassInterface
  25  {
  26      public function process(ContainerBuilder $container)
  27      {
  28          $definitions = new \SplPriorityQueue();
  29          $order = \PHP_INT_MAX;
  30  
  31          foreach ($container->getDefinitions() as $id => $definition) {
  32              if (!$decorated = $definition->getDecoratedService()) {
  33                  continue;
  34              }
  35              $definitions->insert([$id, $definition], [$decorated[2], --$order]);
  36          }
  37          $decoratingDefinitions = [];
  38  
  39          foreach ($definitions as list($id, $definition)) {
  40              list($inner, $renamedId) = $definition->getDecoratedService();
  41  
  42              $definition->setDecoratedService(null);
  43  
  44              if (!$renamedId) {
  45                  $renamedId = $id.'.inner';
  46              }
  47  
  48              // we create a new alias/service for the service we are replacing
  49              // to be able to reference it in the new one
  50              if ($container->hasAlias($inner)) {
  51                  $alias = $container->getAlias($inner);
  52                  $public = $alias->isPublic();
  53                  $private = $alias->isPrivate();
  54                  $container->setAlias($renamedId, new Alias($container->normalizeId($alias), false));
  55              } else {
  56                  $decoratedDefinition = $container->getDefinition($inner);
  57                  $public = $decoratedDefinition->isPublic();
  58                  $private = $decoratedDefinition->isPrivate();
  59                  $decoratedDefinition->setPublic(false);
  60                  $container->setDefinition($renamedId, $decoratedDefinition);
  61                  $decoratingDefinitions[$inner] = $decoratedDefinition;
  62              }
  63  
  64              if (isset($decoratingDefinitions[$inner])) {
  65                  $decoratingDefinition = $decoratingDefinitions[$inner];
  66                  $definition->setTags(array_merge($decoratingDefinition->getTags(), $definition->getTags()));
  67                  $autowiringTypes = $decoratingDefinition->getAutowiringTypes(false);
  68                  if ($types = array_merge($autowiringTypes, $definition->getAutowiringTypes(false))) {
  69                      $definition->setAutowiringTypes($types);
  70                  }
  71                  $decoratingDefinition->setTags([]);
  72                  if ($autowiringTypes) {
  73                      $decoratingDefinition->setAutowiringTypes([]);
  74                  }
  75                  $decoratingDefinitions[$inner] = $definition;
  76              }
  77  
  78              $container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
  79          }
  80      }
  81  }


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