1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace Db3v4l\DependencyInjection; |
||
4 | |||
5 | use Symfony\Component\Console\Command\Command; |
||
0 ignored issues
–
show
The type
Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
6 | use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; |
||
0 ignored issues
–
show
The type
Symfony\Component\Consol...\ContainerCommandLoader was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...r\CompilerPassInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...r\ServiceLocatorTagPass was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
9 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
10 | use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...nvalidArgumentException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
11 | use Symfony\Component\DependencyInjection\TypedReference; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...njection\TypedReference was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
12 | |||
13 | /** |
||
14 | * Just like AddConsoleCommandPass, but only loads 'dbconsole' commands (which use a different tag) |
||
15 | */ |
||
0 ignored issues
–
show
|
|||
16 | class AddDBConsoleCommandPass implements CompilerPassInterface |
||
17 | { |
||
18 | |||
19 | private $commandLoaderServiceId; |
||
0 ignored issues
–
show
|
|||
20 | private $commandTag; |
||
0 ignored issues
–
show
|
|||
21 | |||
22 | public function __construct(string $commandLoaderServiceId = 'dbconsole.command_loader', string $commandTag = 'dbconsole.command') |
||
0 ignored issues
–
show
|
|||
23 | { |
||
24 | $this->commandLoaderServiceId = $commandLoaderServiceId; |
||
25 | $this->commandTag = $commandTag; |
||
26 | } |
||
27 | |||
28 | public function process(ContainerBuilder $container) |
||
0 ignored issues
–
show
|
|||
29 | { |
||
30 | $commandServices = $container->findTaggedServiceIds($this->commandTag, true); |
||
31 | $lazyCommandMap = []; |
||
32 | $lazyCommandRefs = []; |
||
33 | $serviceIds = []; |
||
34 | |||
35 | foreach ($commandServices as $id => $tags) { |
||
36 | $definition = $container->getDefinition($id); |
||
37 | $class = $container->getParameterBag()->resolveValue($definition->getClass()); |
||
38 | |||
39 | if (isset($tags[0]['command'])) { |
||
40 | $commandName = $tags[0]['command']; |
||
41 | } else { |
||
42 | if (!$r = $container->getReflectionClass($class)) { |
||
43 | throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
||
44 | } |
||
45 | if (!$r->isSubclassOf(Command::class)) { |
||
46 | throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
||
47 | } |
||
48 | $commandName = $class::getDefaultName(); |
||
49 | } |
||
50 | |||
51 | // the magic sauce! |
||
52 | $commandName = str_replace('db3v4l:', '', $commandName); |
||
53 | |||
54 | if (null === $commandName) { |
||
55 | if (!$definition->isPublic() || $definition->isPrivate()) { |
||
56 | $commandId = 'dbconsole.command.public_alias.'.$id; |
||
57 | $container->setAlias($commandId, $id)->setPublic(true); |
||
58 | $id = $commandId; |
||
59 | } |
||
60 | $serviceIds[] = $id; |
||
61 | |||
62 | continue; |
||
63 | } |
||
64 | |||
65 | unset($tags[0]); |
||
66 | $lazyCommandMap[$commandName] = $id; |
||
67 | $lazyCommandRefs[$id] = new TypedReference($id, $class); |
||
68 | $aliases = []; |
||
69 | |||
70 | foreach ($tags as $tag) { |
||
71 | if (isset($tag['command'])) { |
||
72 | $aliases[] = $tag['command']; |
||
73 | $lazyCommandMap[$tag['command']] = $id; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $definition->addMethodCall('setName', [$commandName]); |
||
78 | |||
79 | if ($aliases) { |
||
80 | $definition->addMethodCall('setAliases', [$aliases]); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $container |
||
85 | ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) |
||
86 | ->setPublic(true) |
||
87 | ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); |
||
88 | |||
89 | $container->setParameter('dbconsole.command.ids', $serviceIds); |
||
90 | } |
||
91 | } |
||
92 |