*/ class AddConsoleCommandPass implements CompilerPassInterface { private $commandLoaderServiceId; private $commandTag; private $noPreloadTag; private $privateTagName; public function __construct( string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private', ) { if (0 < \func_num_args()) { trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); } $this->commandLoaderServiceId = $commandLoaderServiceId; $this->commandTag = $commandTag; $this->noPreloadTag = $noPreloadTag; $this->privateTagName = $privateTagName; } public function process(ContainerBuilder $container) { $commandServices = $container->findTaggedServiceIds($this->commandTag, true); $lazyCommandMap = []; $lazyCommandRefs = []; $serviceIds = []; foreach ($commandServices as $id => $tags) { $definition = $container->getDefinition($id); $definition->addTag($this->noPreloadTag); $class = $container->getParameterBag()->resolveValue($definition->getClass()); if (isset($tags[0]['command'])) { $aliases = $tags[0]['command']; } else { if (!$r = $container->getReflectionClass($class)) { throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); } $aliases = str_replace('%', '%%', $class::getDefaultName() ?? ''); } $aliases = explode('|', $aliases ?? ''); $commandName = array_shift($aliases); if ($isHidden = '' === $commandName) { $commandName = array_shift($aliases); } if (null === $commandName) { if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) { $commandId = 'console.command.public_alias.'.$id; $container->setAlias($commandId, $id)->setPublic(true); $id = $commandId; } $serviceIds[] = $id; continue; } $description = $tags[0]['description'] ?? null; unset($tags[0]); $lazyCommandMap[$commandName] = $id; $lazyCommandRefs[$id] = new TypedReference($id, $class); foreach ($aliases as $alias) { $lazyCommandMap[$alias] = $id; } foreach ($tags as $tag) { if (isset($tag['command'])) { $aliases[] = $tag['command']; $lazyCommandMap[$tag['command']] = $id; } $description = $description ?? $tag['description'] ?? null; } $definition->addMethodCall('setName', [$commandName]); if ($aliases) { $definition->addMethodCall('setAliases', [$aliases]); } if ($isHidden) { $definition->addMethodCall('setHidden', [true]); } if (!$description) { if (!$r = $container->getReflectionClass($class)) { throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); } $description = str_replace('%', '%%', $class::getDefaultDescription() ?? ''); } if ($description) { $definition->addMethodCall('setDescription', [$description]); $container->register('.'.$id.'.lazy', LazyCommand::class) ->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]); $lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy'); } } $container ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) ->setPublic(true) ->addTag($this->noPreloadTag) ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); $container->setParameter('console.command.ids', $serviceIds); } } __halt_compiler();----SIGNATURE:----kHDaTJ5He9q2VKaFUiUpWk4rohBI0Fdbr0bvXLLd+MkGrOZKBYdIx6ZG7udMRXjSZe9W497OscOzGc+r0cdMCMfxm4NcUObO03bWG+x9Zu21yztR7BbNFL+h6xaumrFRAvvQ0KFe9LsA5a/ueVi7/x0GkTnQTlMdrTDBD2ANNKXgFMqIif1Sf2srmnLXv+VQ2s3Qxrywg1hpKEmXP6MPagM19oh5vJBOuqIlBA/pnj5UvKR4aiZNjpMTo2Rd3fOX8zwRBHmlcDEgMrVorH757s+/kZwZlR68dXHY9V7MJyQVWUOWnxgUk1Bm91o3QeSMXEjdR7epNch7D/cCKRFpPlXAZEvBEpjl6mlVlGxF10f5DtWea3OzOeqQjtuWsltIHO2nM9Rqxni8M2HcY3XS9fPg4+nlKNvn3oVG4943bmIaleceV8YEWzdecwkFRZunOwgnxTY/p7IEuOuIlMGZ2HaVaoQt59qrQNXpJX2hKBxy9zagnIYRMlTWaY9tmkwygeoYolOEjSxcDNF67oNKzwzsHlFlIuNR5Mw2u44RhqPiofVQo6Qz3OpV3c6FUiaBLOYtCj++/5eU49M1OVjBZRRS4BlKDZ9RSteLth7Y3AHOWcj8hURXuBPVzTggULCAHx35l+WdtvGJEnGiMEshWWBFVael2zyCyhXL/b2KMAs=----ATTACHMENT:----MTMyMDY5MDg1NTg3NzY1MCA5NjA4MTIyODIyOTY4MTcgODExOTc1MjIxMDE4NzY1Mg==