From cb10d95b4724d933177a1b1de20a4b7ec4707cc4 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 09:51:47 +0300 Subject: [PATCH 1/7] Pass console argument to startup event --- src/Application.php | 5 +++-- src/Event/ApplicationStartup.php | 6 ++++++ tests/ApplicationTest.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Application.php b/src/Application.php index 5c17fe7af..31bf3fa3f 100644 --- a/src/Application.php +++ b/src/Application.php @@ -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; @@ -35,10 +36,10 @@ public function setDispatcher(EventDispatcherInterface $dispatcher): void parent::setDispatcher($dispatcher); } - public function start(): void + public function start(ArgvInput $input): void { if ($this->dispatcher !== null) { - $this->dispatcher->dispatch(new ApplicationStartup()); + $this->dispatcher->dispatch(new ApplicationStartup($input->getArguments(), $input->getOptions())); } } diff --git a/src/Event/ApplicationStartup.php b/src/Event/ApplicationStartup.php index 8f6915702..ec14a1a2b 100644 --- a/src/Event/ApplicationStartup.php +++ b/src/Event/ApplicationStartup.php @@ -6,4 +6,10 @@ final class ApplicationStartup { + public function __construct( + public array $arguments = [], + public array $options = [], + ) + { + } } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 4de5ea942..6857218dc 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -13,7 +13,7 @@ final class ApplicationTest extends TestCase { public function testDispatcherEventApplicationStartup(): void { - $event = new ApplicationStartup(); + $event = new ApplicationStartup([], []); $result = $this ->getInaccessibleProperty($this->application(), 'dispatcher') From 321609b8775a8fb9acfea3eb023991a3eb5ace8a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 29 Jul 2022 06:52:59 +0000 Subject: [PATCH 2/7] Apply fixes from StyleCI --- src/Event/ApplicationStartup.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Event/ApplicationStartup.php b/src/Event/ApplicationStartup.php index ec14a1a2b..c055bf9a4 100644 --- a/src/Event/ApplicationStartup.php +++ b/src/Event/ApplicationStartup.php @@ -9,7 +9,6 @@ final class ApplicationStartup public function __construct( public array $arguments = [], public array $options = [], - ) - { + ) { } } From b5b07061ba0a6a58d1f0a14db1cbf4737234a2e1 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 09:58:43 +0300 Subject: [PATCH 3/7] Add changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 975cc4dc5..beb305bb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Yii Console Change Log -## 1.2.1 under development +## 2.0.0 under development -- no changes in this release. +- Chg: #159: Add collecting console arguments and options to `ApplicationStartup` class (@xepozz) ## 1.2.0 July 21, 2022 From 0f53979fcf62756d8924145cf2474d2803f649cb Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 12:24:33 +0300 Subject: [PATCH 4/7] Refactor event arguments --- src/Application.php | 2 +- src/Event/ApplicationStartup.php | 3 +-- tests/ApplicationTest.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Application.php b/src/Application.php index 31bf3fa3f..afd7f3396 100644 --- a/src/Application.php +++ b/src/Application.php @@ -39,7 +39,7 @@ public function setDispatcher(EventDispatcherInterface $dispatcher): void public function start(ArgvInput $input): void { if ($this->dispatcher !== null) { - $this->dispatcher->dispatch(new ApplicationStartup($input->getArguments(), $input->getOptions())); + $this->dispatcher->dispatch(new ApplicationStartup($input->getFirstArgument())); } } diff --git a/src/Event/ApplicationStartup.php b/src/Event/ApplicationStartup.php index c055bf9a4..dcd36017d 100644 --- a/src/Event/ApplicationStartup.php +++ b/src/Event/ApplicationStartup.php @@ -7,8 +7,7 @@ final class ApplicationStartup { public function __construct( - public array $arguments = [], - public array $options = [], + public ?string $commandName = null, ) { } } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 6857218dc..4662a0f6d 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -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') From c66b135b04f2b8749b1fd96b01c490ff0cf9e010 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 12:58:45 +0300 Subject: [PATCH 5/7] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beb305bb5..ca8f7b34d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.0 under development -- Chg: #159: Add collecting console arguments and options to `ApplicationStartup` class (@xepozz) +- Chg: #159: Add collecting console command name to `ApplicationStartup` class (@xepozz) ## 1.2.0 July 21, 2022 From f81f82ba546e1d4a18b5c2a2c58ffb39853d5911 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 13:21:08 +0300 Subject: [PATCH 6/7] Fix error --- src/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application.php b/src/Application.php index afd7f3396..6130ac543 100644 --- a/src/Application.php +++ b/src/Application.php @@ -36,9 +36,9 @@ public function setDispatcher(EventDispatcherInterface $dispatcher): void parent::setDispatcher($dispatcher); } - public function start(ArgvInput $input): void + public function start(?ArgvInput $input = null): void { - if ($this->dispatcher !== null) { + if ($this->dispatcher !== null && $input !== null) { $this->dispatcher->dispatch(new ApplicationStartup($input->getFirstArgument())); } } From 9326f05233eb4d725d51faa33cad0af115f0d6c8 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Fri, 29 Jul 2022 13:43:30 +0300 Subject: [PATCH 7/7] Fix version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca8f7b34d..9777d11ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Yii Console Change Log -## 2.0.0 under development +## 1.2.1 under development - Chg: #159: Add collecting console command name to `ApplicationStartup` class (@xepozz)