Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

RegisterServiceSubscribersPass.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 4.93 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\DependencyInjection\Compiler;
 013   
 014  use Symfony\Component\DependencyInjection\ContainerInterface;
 015  use Symfony\Component\DependencyInjection\Definition;
 016  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 017  use Symfony\Component\DependencyInjection\Reference;
 018  use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
 019  use Symfony\Component\DependencyInjection\TypedReference;
 020   
 021  /**
 022   * Compiler pass to register tagged services that require a service locator.
 023   *
 024   * @author Nicolas Grekas <p@tchwork.com>
 025   */
 026  class RegisterServiceSubscribersPass extends AbstractRecursivePass
 027  {
 028      protected function processValue($value, $isRoot = false)
 029      {
 030          if (!$value instanceof Definition || $value->isAbstract() || $value->isSynthetic() || !$value->hasTag('container.service_subscriber')) {
 031              return parent::processValue($value, $isRoot);
 032          }
 033   
 034          $serviceMap = [];
 035          $autowire = $value->isAutowired();
 036   
 037          foreach ($value->getTag('container.service_subscriber') as $attributes) {
 038              if (!$attributes) {
 039                  $autowire = true;
 040                  continue;
 041              }
 042              ksort($attributes);
 043              if ([] !== array_diff(array_keys($attributes), ['id', 'key'])) {
 044                  throw new InvalidArgumentException(sprintf('The "container.service_subscriber" tag accepts only the "key" and "id" attributes, "%s" given for service "%s".', implode('", "', array_keys($attributes)), $this->currentId));
 045              }
 046              if (!\array_key_exists('id', $attributes)) {
 047                  throw new InvalidArgumentException(sprintf('Missing "id" attribute on "container.service_subscriber" tag with key="%s" for service "%s".', $attributes['key'], $this->currentId));
 048              }
 049              if (!\array_key_exists('key', $attributes)) {
 050                  $attributes['key'] = $attributes['id'];
 051              }
 052              if (isset($serviceMap[$attributes['key']])) {
 053                  continue;
 054              }
 055              $serviceMap[$attributes['key']] = new Reference($attributes['id']);
 056          }
 057          $class = $value->getClass();
 058   
 059          if (!$r = $this->container->getReflectionClass($class)) {
 060              throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId));
 061          }
 062          if (!$r->isSubclassOf(ServiceSubscriberInterface::class)) {
 063              throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class));
 064          }
 065          $class = $r->name;
 066   
 067          $subscriberMap = [];
 068          $declaringClass = (new \ReflectionMethod($class, 'getSubscribedServices'))->class;
 069   
 070          foreach ($class::getSubscribedServices() as $key => $type) {
 071              if (!\is_string($type) || !preg_match('/^\??[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $type)) {
 072                  throw new InvalidArgumentException(sprintf('"%s::getSubscribedServices()" must return valid PHP types for service "%s" key "%s", "%s" returned.', $class, $this->currentId, $key, \is_string($type) ? $type : \gettype($type)));
 073              }
 074              if ($optionalBehavior = '?' === $type[0]) {
 075                  $type = substr($type, 1);
 076                  $optionalBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
 077              }
 078              if (\is_int($key)) {
 079                  $key = $type;
 080              }
 081              if (!isset($serviceMap[$key])) {
 082                  if (!$autowire) {
 083                      throw new InvalidArgumentException(sprintf('Service "%s" misses a "container.service_subscriber" tag with "key"/"id" attributes corresponding to entry "%s" as returned by "%s::getSubscribedServices()".', $this->currentId, $key, $class));
 084                  }
 085                  $serviceMap[$key] = new Reference($type);
 086              }
 087   
 088              $subscriberMap[$key] = new TypedReference($this->container->normalizeId($serviceMap[$key]), $type, $declaringClass, $optionalBehavior ?: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
 089              unset($serviceMap[$key]);
 090          }
 091   
 092          if ($serviceMap = array_keys($serviceMap)) {
 093              $message = sprintf(1 < \count($serviceMap) ? 'keys "%s" do' : 'key "%s" does', str_replace('%', '%%', implode('", "', $serviceMap)));
 094              throw new InvalidArgumentException(sprintf('Service %s not exist in the map returned by "%s::getSubscribedServices()" for service "%s".', $message, $class, $this->currentId));
 095          }
 096   
 097          $value->addTag('container.service_subscriber.locator', ['id' => (string) ServiceLocatorTagPass::register($this->container, $subscriberMap, $this->currentId)]);
 098   
 099          return parent::processValue($value);
 100      }
 101  }
 102