[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/DependencyInjection/ -> FragmentRendererPass.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\Compiler\CompilerPassInterface;
  15  use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
  16  use Symfony\Component\DependencyInjection\ContainerBuilder;
  17  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  18  use Symfony\Component\DependencyInjection\Reference;
  19  use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
  20  
  21  /**
  22   * Adds services tagged kernel.fragment_renderer as HTTP content rendering strategies.
  23   *
  24   * @author Fabien Potencier <fabien@symfony.com>
  25   */
  26  class FragmentRendererPass implements CompilerPassInterface
  27  {
  28      private $handlerService;
  29      private $rendererTag;
  30  
  31      /**
  32       * @param string $handlerService Service name of the fragment handler in the container
  33       * @param string $rendererTag    Tag name used for fragments
  34       */
  35      public function __construct($handlerService = 'fragment.handler', $rendererTag = 'kernel.fragment_renderer')
  36      {
  37          $this->handlerService = $handlerService;
  38          $this->rendererTag = $rendererTag;
  39      }
  40  
  41      public function process(ContainerBuilder $container)
  42      {
  43          if (!$container->hasDefinition($this->handlerService)) {
  44              return;
  45          }
  46  
  47          $definition = $container->getDefinition($this->handlerService);
  48          $renderers = [];
  49          foreach ($container->findTaggedServiceIds($this->rendererTag, true) as $id => $tags) {
  50              $def = $container->getDefinition($id);
  51              $class = $container->getParameterBag()->resolveValue($def->getClass());
  52  
  53              if (!$r = $container->getReflectionClass($class)) {
  54                  throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
  55              }
  56              if (!$r->isSubclassOf(FragmentRendererInterface::class)) {
  57                  throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, FragmentRendererInterface::class));
  58              }
  59  
  60              foreach ($tags as $tag) {
  61                  $renderers[$tag['alias']] = new Reference($id);
  62              }
  63          }
  64  
  65          $definition->replaceArgument(0, ServiceLocatorTagPass::register($container, $renderers));
  66      }
  67  }


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