Skip to content

Commit c146951

Browse files
committed
Add option to set commands by FQCN or instance
1 parent 115ed6b commit c146951

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

guide/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ Console Config Options
530530
'default' => [
531531
'directories' => null,
532532
'find_in_namespaces' => false,
533+
'commands' => null,
533534
'language_instance' => 'default',
534535
'locator_instance' => 'default',
535536
],
@@ -548,6 +549,14 @@ find_in_namespaces
548549
Set ``true`` to find commands in all Commands subdirectories of all namespaces.
549550
The default is not to find in namespaces.
550551

552+
commands
553+
""""""""
554+
555+
Sets an array of Fully Qualified Class Names or instances of the
556+
Framework\CLICommand class. By default, no additional classes are set.
557+
558+
These commands are added after searching through namespaces and directories.
559+
551560
language_instance
552561
"""""""""""""""""
553562

src/App.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ protected static function setConsole(string $instance) : Console
506506
}
507507
}
508508
}
509+
if (isset($config['commands'])) {
510+
foreach ($config['commands'] as $command) {
511+
$service->addCommand($command);
512+
}
513+
}
509514
return static::setService('console', $service, $instance);
510515
}
511516

tests/configs/console.config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
'/unknown',
1515
],
1616
'find_in_namespaces' => true,
17+
'commands' => [
18+
Tests\MVC\Commands\Hello::class,
19+
],
1720
'language_instance' => 'default',
1821
'locator_instance' => 'default',
1922
],

0 commit comments

Comments
 (0)