Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command arguments #159

Merged
merged 7 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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