diff --git a/CHANGELOG.md b/CHANGELOG.md index e987e7c..d6bca29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.1 under development -- no changes in this release. +- Enh #61: Move events group name to component params (@olegbaturin) ## 2.0.0 February 16, 2023 diff --git a/composer.json b/composer.json index 3ae8dae..5c6ec06 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,8 @@ "merge-plan-file": "../tests/environment/.merge-plan.php" }, "config-plugin": { + "params-web": "params-web.php", + "params-console": "params-console.php", "di": "di.php", "di-web": "di-web.php", "di-console": "di-console.php", diff --git a/config/di-console.php b/config/di-console.php index 4e41a2b..9e482bb 100644 --- a/config/di-console.php +++ b/config/di-console.php @@ -6,7 +6,8 @@ use Yiisoft\Yii\Event\ListenerCollectionFactory as Factory; /** @var \Yiisoft\Config\Config $config */ +/** @var array $params */ return [ - ListenerCollection::class => static fn (Factory $factory) => $factory->create($config->get('events-console')), + ListenerCollection::class => static fn (Factory $factory) => $factory->create($config->get($params['yiisoft/yii-event']['eventsGroup'])), ]; diff --git a/config/di-web.php b/config/di-web.php index 70b4097..9e482bb 100644 --- a/config/di-web.php +++ b/config/di-web.php @@ -6,7 +6,8 @@ use Yiisoft\Yii\Event\ListenerCollectionFactory as Factory; /** @var \Yiisoft\Config\Config $config */ +/** @var array $params */ return [ - ListenerCollection::class => static fn (Factory $factory) => $factory->create($config->get('events-web')), + ListenerCollection::class => static fn (Factory $factory) => $factory->create($config->get($params['yiisoft/yii-event']['eventsGroup'])), ]; diff --git a/config/params-console.php b/config/params-console.php new file mode 100644 index 0000000..1ff5ed2 --- /dev/null +++ b/config/params-console.php @@ -0,0 +1,9 @@ + [ + 'eventsGroup' => 'events-console', + ], +]; diff --git a/config/params-web.php b/config/params-web.php new file mode 100644 index 0000000..5e9271b --- /dev/null +++ b/config/params-web.php @@ -0,0 +1,9 @@ + [ + 'eventsGroup' => 'events-web', + ], +]; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 12dcc0d..cf913be 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -51,7 +51,7 @@ private function createContainer(?string $postfix = null): Container { return new Container( ContainerConfig::create()->withDefinitions( - $this->createConfig()->get('di' . ($postfix !== null ? '-' . $postfix : '')) + $this->createConfig($postfix)->get('di' . ($postfix !== null ? '-' . $postfix : '')) + [ EventDispatcherInterface::class => new SimpleEventDispatcher(), @@ -60,13 +60,13 @@ private function createContainer(?string $postfix = null): Container ); } - private function createConfig(): Config + private function createConfig(?string $postfix = null): Config { return new Config( new ConfigPaths(dirname(__DIR__), 'config'), null, [], - null, + $postfix !== null ? 'params' . '-' . $postfix : null, '../tests/environment/.merge-plan.php' ); }