Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

AddConsoleCommandPass.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.90 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\Console\DependencyInjection;
013   
014  use Symfony\Component\Console\Command\Command;
015  use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
016  use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
017  use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
018  use Symfony\Component\DependencyInjection\ContainerBuilder;
019  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
020  use Symfony\Component\DependencyInjection\TypedReference;
021   
022  /**
023   * Registers console commands.
024   *
025   * @author Grégoire Pineau <lyrixx@lyrixx.info>
026   */
027  class AddConsoleCommandPass implements CompilerPassInterface
028  {
029      private $commandLoaderServiceId;
030      private $commandTag;
031   
032      public function __construct($commandLoaderServiceId = 'console.command_loader', $commandTag = 'console.command')
033      {
034          $this->commandLoaderServiceId = $commandLoaderServiceId;
035          $this->commandTag = $commandTag;
036      }
037   
038      public function process(ContainerBuilder $container)
039      {
040          $commandServices = $container->findTaggedServiceIds($this->commandTag, true);
041          $lazyCommandMap = [];
042          $lazyCommandRefs = [];
043          $serviceIds = [];
044          $lazyServiceIds = [];
045   
046          foreach ($commandServices as $id => $tags) {
047              $definition = $container->getDefinition($id);
048              $class = $container->getParameterBag()->resolveValue($definition->getClass());
049   
050              $commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
051   
052              if (isset($tags[0]['command'])) {
053                  $commandName = $tags[0]['command'];
054              } else {
055                  if (!$r = $container->getReflectionClass($class)) {
056                      throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
057                  }
058                  if (!$r->isSubclassOf(Command::class)) {
059                      throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
060                  }
061                  $commandName = $class::getDefaultName();
062              }
063   
064              if (null === $commandName) {
065                  if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
066                      $commandId = $commandId.'_'.$id;
067                  }
068                  if (!$definition->isPublic() || $definition->isPrivate()) {
069                      $container->setAlias($commandId, $id)->setPublic(true);
070                      $id = $commandId;
071                  }
072                  $serviceIds[$commandId] = $id;
073   
074                  continue;
075              }
076   
077              $serviceIds[$commandId] = $id;
078              $lazyServiceIds[$id] = true;
079              unset($tags[0]);
080              $lazyCommandMap[$commandName] = $id;
081              $lazyCommandRefs[$id] = new TypedReference($id, $class);
082              $aliases = [];
083   
084              foreach ($tags as $tag) {
085                  if (isset($tag['command'])) {
086                      $aliases[] = $tag['command'];
087                      $lazyCommandMap[$tag['command']] = $id;
088                  }
089              }
090   
091              $definition->addMethodCall('setName', [$commandName]);
092   
093              if ($aliases) {
094                  $definition->addMethodCall('setAliases', [$aliases]);
095              }
096          }
097   
098          $container
099              ->register($this->commandLoaderServiceId, ContainerCommandLoader::class)
100              ->setPublic(true)
101              ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]);
102   
103          $container->setParameter('console.command.ids', $serviceIds);
104          $container->setParameter('console.lazy_command.ids', $lazyServiceIds);
105      }
106  }
107