Skip to content

Commit

Permalink
Merge pull request #159 from yiisoft/add-command-arguments
Browse files Browse the repository at this point in the history
Add command name
  • Loading branch information
xepozz committed Jul 29, 2022
2 parents bf7b4ed + 9326f05 commit f979967
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

## 1.2.1 under development

- no changes in this release.
- Chg: #159: Add collecting console command name to `ApplicationStartup` class (@xepozz)

## 1.2.0 July 21, 2022

Expand Down
7 changes: 4 additions & 3 deletions src/Application.php
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\Console;

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
Expand Down Expand Up @@ -35,10 +36,10 @@ public function setDispatcher(EventDispatcherInterface $dispatcher): void
parent::setDispatcher($dispatcher);
}

public function start(): void
public function start(?ArgvInput $input = null): void
{
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new ApplicationStartup());
if ($this->dispatcher !== null && $input !== null) {
$this->dispatcher->dispatch(new ApplicationStartup($input->getFirstArgument()));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Event/ApplicationStartup.php
Expand Up @@ -6,4 +6,8 @@

final class ApplicationStartup
{
public function __construct(
public ?string $commandName = null,
) {
}
}
2 changes: 1 addition & 1 deletion tests/ApplicationTest.php
Expand Up @@ -13,7 +13,7 @@ final class ApplicationTest extends TestCase
{
public function testDispatcherEventApplicationStartup(): void
{
$event = new ApplicationStartup();
$event = new ApplicationStartup(null);

$result = $this
->getInaccessibleProperty($this->application(), 'dispatcher')
Expand Down

0 comments on commit f979967

Please sign in to comment.