Skip to content

Commit

Permalink
Use Console setter when adding Command
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed May 12, 2022
1 parent 66cdbf5 commit 9569b0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ abstract class Command
/**
* Command constructor.
*
* @param Console $console
* @param Console|null $console
*/
public function __construct(Console $console)
public function __construct(Console $console = null)
{
$this->console = $console;
if ($console) {
$this->console = $console;
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ public function getLanguage() : Language
public function addCommand(Command | string $command) : static
{
if (\is_string($command)) {
$command = new $command($this);
$command = new $command();
}
$command->setConsole($this);
$this->commands[$command->getName()] = $command;
return $this;
}
Expand Down

0 comments on commit 9569b0c

Please sign in to comment.