Skip to content

Commit

Permalink
ConsoleExtension: support commad tags (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
janzarubadek authored Jan 4, 2024
1 parent e52267a commit 07ec27b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Nette\Http\RequestFactory;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\Utils\Arrays;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
Expand Down Expand Up @@ -144,17 +145,27 @@ public function beforeCompile(): void

// Iterate over all commands and build commandMap
foreach ($commands as $serviceName => $service) {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line

if ($commandName === null) {
throw new ServiceCreationException(
sprintf(
'Command "%s" missing #[AsCommand] attribute',
$service->getType(),
)
);
$tags = $service->getTags();
$commandDef = $tags['console.command'] ?? null;
$commandName = null;
if ($commandDef !== null) {

Check failure on line 151 in src/DI/ConsoleExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Expected 1 line after "if", found 0.
if (is_string($commandDef)) {
$commandName = $commandDef;
} elseif (is_array($commandDef)) {
$commandName = Arrays::get($tags['console.command'], 'name', null);
}
} else {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line

if ($commandName === null) {
throw new ServiceCreationException(
sprintf(
'Command "%s" missing #[AsCommand] attribute',
$service->getType(),
)
);
}
}

// Append service to command map
$commandMap[$commandName] = $serviceName;
}
Expand Down

0 comments on commit 07ec27b

Please sign in to comment.