3030class Kernel implements \Mantle \Contracts \Console \Kernel {
3131 use Loads_Classes;
3232
33- /**
34- * The application implementation.
35- *
36- * @var Application|null
37- */
38- protected $ app ;
39-
4033 /**
4134 * The bootstrap classes for the application.
4235 *
43- * @var array
36+ * @var array<class-string>
4437 */
4538 protected $ bootstrappers = [
4639 \Mantle \Framework \Bootstrap \Load_Configuration::class,
@@ -53,7 +46,7 @@ class Kernel implements \Mantle\Contracts\Console\Kernel {
5346 /**
5447 * The commands provided by the application.
5548 *
56- * @var array
49+ * @var array<class-string<\Mantle\Console\Command>|Command>
5750 */
5851 protected $ commands = [];
5952
@@ -77,9 +70,7 @@ class Kernel implements \Mantle\Contracts\Console\Kernel {
7770 *
7871 * @param Application $app Application instance.
7972 */
80- public function __construct ( Application $ app ) {
81- $ this ->app = $ app ;
82-
73+ public function __construct ( protected Application $ app ) {
8374 $ this ->ensure_environment_is_set ();
8475 }
8576
@@ -127,6 +118,23 @@ public function test( string $command, array $parameters = [] ): CommandTester {
127118 return $ this ->get_console_application ()->test ( $ command , $ parameters );
128119 }
129120
121+ /**
122+ * Register a new command with the console application.
123+ *
124+ * @throws \InvalidArgumentException Thrown if the command is not a valid command.
125+ *
126+ * @param Command|class-string<Command> $command Command instance or class name.
127+ */
128+ public function register ( Command |string $ command ): void {
129+ if ( ! class_exists ( $ command ) || ! is_subclass_of ( $ command , Command::class ) ) { // @phpstan-ignore-line function.alreadyNarrowedType
130+ throw new \InvalidArgumentException ( "Command [ {$ command }] is not a valid command. " );
131+ }
132+
133+ Console_Application::starting (
134+ fn ( Console_Application $ app ) => $ app ->resolve ( $ command )
135+ );
136+ }
137+
130138 /**
131139 * Register a new Closure based command with a signature.
132140 *
0 commit comments