Skip to content

Commit 9569b0c

Browse files
committed
Use Console setter when adding Command
1 parent 66cdbf5 commit 9569b0c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Command.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ abstract class Command
4848
/**
4949
* Command constructor.
5050
*
51-
* @param Console $console
51+
* @param Console|null $console
5252
*/
53-
public function __construct(Console $console)
53+
public function __construct(Console $console = null)
5454
{
55-
$this->console = $console;
55+
if ($console) {
56+
$this->console = $console;
57+
}
5658
}
5759

5860
/**

src/Console.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ public function getLanguage() : Language
135135
public function addCommand(Command | string $command) : static
136136
{
137137
if (\is_string($command)) {
138-
$command = new $command($this);
138+
$command = new $command();
139139
}
140+
$command->setConsole($this);
140141
$this->commands[$command->getName()] = $command;
141142
return $this;
142143
}

0 commit comments

Comments
 (0)