Skip to content

Commit

Permalink
Move events group name to component params (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbaturin committed Sep 15, 2023
1 parent d3f8300 commit 10db0d7
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion config/di-console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])),
];
3 changes: 2 additions & 1 deletion config/di-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])),
];
9 changes: 9 additions & 0 deletions config/params-console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

return [
'yiisoft/yii-event' => [
'eventsGroup' => 'events-console',
],
];
9 changes: 9 additions & 0 deletions config/params-web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

return [
'yiisoft/yii-event' => [
'eventsGroup' => 'events-web',
],
];
6 changes: 3 additions & 3 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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'
);
}
Expand Down

0 comments on commit 10db0d7

Please sign in to comment.