PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / console / DependencyInjection / AddConsoleCommandPass.php
matomo / app / vendor / prefixed / symfony / console / DependencyInjection Last commit date
AddConsoleCommandPass.php 1 year ago
AddConsoleCommandPass.php
119 lines
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 namespace Matomo\Dependencies\Symfony\Component\Console\DependencyInjection;
12
13 use Matomo\Dependencies\Symfony\Component\Console\Command\Command;
14 use Matomo\Dependencies\Symfony\Component\Console\Command\LazyCommand;
15 use Matomo\Dependencies\Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
16 use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
17 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18 use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
21 use Symfony\Component\DependencyInjection\Reference;
22 use Symfony\Component\DependencyInjection\TypedReference;
23 /**
24 * Registers console commands.
25 *
26 * @author Grégoire Pineau <lyrixx@lyrixx.info>
27 */
28 class AddConsoleCommandPass implements CompilerPassInterface
29 {
30 private $commandLoaderServiceId;
31 private $commandTag;
32 private $noPreloadTag;
33 private $privateTagName;
34 public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private')
35 {
36 if (0 < \func_num_args()) {
37 trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
38 }
39 $this->commandLoaderServiceId = $commandLoaderServiceId;
40 $this->commandTag = $commandTag;
41 $this->noPreloadTag = $noPreloadTag;
42 $this->privateTagName = $privateTagName;
43 }
44 public function process(ContainerBuilder $container)
45 {
46 $commandServices = $container->findTaggedServiceIds($this->commandTag, \true);
47 $lazyCommandMap = [];
48 $lazyCommandRefs = [];
49 $serviceIds = [];
50 foreach ($commandServices as $id => $tags) {
51 $definition = $container->getDefinition($id);
52 $definition->addTag($this->noPreloadTag);
53 $class = $container->getParameterBag()->resolveValue($definition->getClass());
54 if (isset($tags[0]['command'])) {
55 $aliases = $tags[0]['command'];
56 } else {
57 if (!($r = $container->getReflectionClass($class))) {
58 throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
59 }
60 if (!$r->isSubclassOf(Command::class)) {
61 throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
62 }
63 $aliases = str_replace('%', '%%', $class::getDefaultName() ?? '');
64 }
65 $aliases = explode('|', $aliases ?? '');
66 $commandName = array_shift($aliases);
67 if ($isHidden = '' === $commandName) {
68 $commandName = array_shift($aliases);
69 }
70 if (null === $commandName) {
71 if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) {
72 $commandId = 'console.command.public_alias.' . $id;
73 $container->setAlias($commandId, $id)->setPublic(\true);
74 $id = $commandId;
75 }
76 $serviceIds[] = $id;
77 continue;
78 }
79 $description = $tags[0]['description'] ?? null;
80 unset($tags[0]);
81 $lazyCommandMap[$commandName] = $id;
82 $lazyCommandRefs[$id] = new TypedReference($id, $class);
83 foreach ($aliases as $alias) {
84 $lazyCommandMap[$alias] = $id;
85 }
86 foreach ($tags as $tag) {
87 if (isset($tag['command'])) {
88 $aliases[] = $tag['command'];
89 $lazyCommandMap[$tag['command']] = $id;
90 }
91 $description = $description ?? $tag['description'] ?? null;
92 }
93 $definition->addMethodCall('setName', [$commandName]);
94 if ($aliases) {
95 $definition->addMethodCall('setAliases', [$aliases]);
96 }
97 if ($isHidden) {
98 $definition->addMethodCall('setHidden', [\true]);
99 }
100 if (!$description) {
101 if (!($r = $container->getReflectionClass($class))) {
102 throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
103 }
104 if (!$r->isSubclassOf(Command::class)) {
105 throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
106 }
107 $description = str_replace('%', '%%', $class::getDefaultDescription() ?? '');
108 }
109 if ($description) {
110 $definition->addMethodCall('setDescription', [$description]);
111 $container->register('.' . $id . '.lazy', LazyCommand::class)->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]);
112 $lazyCommandRefs[$id] = new Reference('.' . $id . '.lazy');
113 }
114 }
115 $container->register($this->commandLoaderServiceId, ContainerCommandLoader::class)->setPublic(\true)->addTag($this->noPreloadTag)->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]);
116 $container->setParameter('console.command.ids', $serviceIds);
117 }
118 }
119