[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/DependencyInjection/ -> ResettableServicePass.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\HttpKernel\DependencyInjection;
  13  
  14  use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
  15  use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  16  use Symfony\Component\DependencyInjection\ContainerBuilder;
  17  use Symfony\Component\DependencyInjection\ContainerInterface;
  18  use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  19  use Symfony\Component\DependencyInjection\Reference;
  20  
  21  /**
  22   * @author Alexander M. Turek <me@derrabus.de>
  23   */
  24  class ResettableServicePass implements CompilerPassInterface
  25  {
  26      private $tagName;
  27  
  28      public function __construct($tagName = 'kernel.reset')
  29      {
  30          $this->tagName = $tagName;
  31      }
  32  
  33      /**
  34       * {@inheritdoc}
  35       */
  36      public function process(ContainerBuilder $container)
  37      {
  38          if (!$container->has('services_resetter')) {
  39              return;
  40          }
  41  
  42          $services = $methods = [];
  43  
  44          foreach ($container->findTaggedServiceIds($this->tagName, true) as $id => $tags) {
  45              $services[$id] = new Reference($id, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE);
  46              $attributes = $tags[0];
  47  
  48              if (!isset($attributes['method'])) {
  49                  throw new RuntimeException(sprintf('Tag "%s" requires the "method" attribute to be set.', $this->tagName));
  50              }
  51  
  52              $methods[$id] = $attributes['method'];
  53          }
  54  
  55          if (empty($services)) {
  56              $container->removeAlias('services_resetter');
  57              $container->removeDefinition('services_resetter');
  58  
  59              return;
  60          }
  61  
  62          $container->findDefinition('services_resetter')
  63              ->setArgument(0, new IteratorArgument($services))
  64              ->setArgument(1, $methods);
  65      }
  66  }


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