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 parameters $useBootstrap, $checkEvents and $configGroupPostfix to the HttpApplicationRunner #43

Merged
merged 15 commits into from
Feb 19, 2023
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Yii Runner HTTP Change Log

## 1.2.0 under development

- Enh #39: Adapt to `yiisoft/yii-runner` of version `^2.0` (@vjik)
- New #40: In the `HttpApplicationRunner` constructor make parameter "environment" optional (`null` by default) and add
new parameters that set config group names for container, bootstrap and events (@vjik)
- New #42: In the `HttpApplicationRunner` constructor add parameter that set config params group name (@vjik)
## 2.0.0 under development

- New #40: In the `HttpApplicationRunner` constructor make parameter "environment" optional, default `null` (@vjik)
- New #42, #43: Add ability to configure all config group names (@vjik)
- New #43: Add parameter `$checkEvents` to `HttpApplicationRunner` constructor (@vjik)
- New #43: In the `HttpApplicationRunner` constructor make parameter "debug" optional, default `false` (@vjik)
- Chg #39, #43: Raise required version of `yiisoft/yii-runner` to `^2.0`, `yiisoft/log-target-file` to `^3.0`
and `yiisoft/error-handler` to `^3.0` (@vjik)

## 1.1.2 November 10, 2022

Expand Down
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The package contains a bootstrap for running Yii3 HTTP application.
The package could be installed with composer:

```shell
composer require yiisoft/yii-runner-http --prefer-dist
composer require yiisoft/yii-runner-http
```

## General usage
Expand All @@ -43,44 +43,54 @@ use Yiisoft\Yii\Runner\Http\HttpApplicationRunner;

require_once __DIR__ . '/autoload.php';

(new HttpApplicationRunner(__DIR__, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']))->run();
(new HttpApplicationRunner(
rootPath: __DIR__,
debug: $_ENV['YII_DEBUG'],
checkEvents: $_ENV['YII_DEBUG'],
environment: $_ENV['YII_ENV']
))->run();
```

### Additional configuration

By default, the `HttpApplicationRunner` is configured to work with Yii application templates.
You can override the default configuration using immutable setters.
By default, the `HttpApplicationRunner` is configured to work with Yii application templates and follows the
[config groups convention](https://github.com/yiisoft/docs/blob/master/022-config-groups.md).

Override the name of the bootstrap configuration group as follows:
You can override the default configuration using constructor parameters and immutable setters.

```php
/**
* @var Yiisoft\Yii\Runner\Http\HttpApplicationRunner $runner
*/
#### Constructor parameters

// Bootstrap configuration group name by default is "bootstrap-web".
$runner = $runner->withBootstrap('my-bootstrap-config-group-name');
`$rootPath` — the absolute path to the project root.

// Disables the use of bootstrap configuration group.
$runner = $runner->withoutBootstrap();
```
`$debug` — whether the debug mode is enabled.

In debug mode, event configurations are checked, to override, use the following setters:
`$checkEvents` — whether check events' configuration.

```php
/**
* @var Yiisoft\Yii\Runner\Http\HttpApplicationRunner $runner
*/
`$environment` — the environment name.

// Configuration group name of events by default is "events-web".
$runner = $runner->withCheckingEvents('my-events-config-group-name');
`$bootstrapGroup` — the bootstrap configuration group name.

// Disables checking of the event configuration group.
$runner = $runner->withoutCheckingEvents();
```
`$eventsGroup` — the events' configuration group name.

`$diGroup` — the container definitions' configuration group name.

`$diProvidersGroup` — the container providers' configuration group name.

`$diDelegatesGroup` — the container delegates' configuration group name.

`$diTagsGroup` — the container tags' configuration group name.

`$paramsGroup` — the config parameters group name.

`$nestedParamsGroups` — configuration group names that are included into config parameters group. This is needed for
recursive merge parameters.

`$nestedEventsGroups` — configuration group names that are included into events' configuration group. This is needed for
reverse and recursive merge events' configurations.

#### Immutable setters

If the configuration instance settings differ from the default, such as configuration group names,
you can specify a customized configuration instance:
If the configuration instance settings differ from the default you can specify a customized configuration instance:

```php
/**
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"yiisoft/config": "^1.1",
"yiisoft/definitions": "^1.0|^2.0|^3.0",
"yiisoft/di": "^1.0",
"yiisoft/error-handler": "^2.1",
"yiisoft/error-handler": "^3.0",
"yiisoft/friendly-exception": "^1.1",
"yiisoft/http": "^1.2",
"yiisoft/log": "^2.0",
"yiisoft/log-target-file": "^1.1|^2.0",
"yiisoft/log-target-file": "^3.0",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-runner": "^1.0"
"yiisoft/yii-runner": "^2.0"
},
"require-dev": {
"httpsoft/http-message": "^1.0",
Expand All @@ -50,7 +50,7 @@
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.2",
"yiisoft/middleware-dispatcher": "^4.0",
"yiisoft/middleware-dispatcher": "^5.0",
"yiisoft/test-support": "^3.0"
},
"autoload": {
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
54 changes: 41 additions & 13 deletions src/HttpApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,53 @@ final class HttpApplicationRunner extends ApplicationRunner
/**
* @param string $rootPath The absolute path to the project root.
* @param bool $debug Whether the debug mode is enabled.
* @param string $paramsConfigGroup The config parameters group name.
* @param string $containerConfigGroup The container configuration group name.
* @param string|null $bootstrapGroup The bootstrap configuration group name.
* @param string|null $eventsGroup The event configuration group name to check. The configuration of events is
* checked in debug mode only.
* @param bool $checkEvents Whether to check events' configuration.
* @param string|null $environment The environment name.
* @param string $bootstrapGroup The bootstrap configuration group name.
* @param string $eventsGroup The events' configuration group name.
* @param string $diGroup The container definitions' configuration group name.
* @param string $diProvidersGroup The container providers' configuration group name.
* @param string $diDelegatesGroup The container delegates' configuration group name.
* @param string $diTagsGroup The container tags' configuration group name.
* @param string $paramsGroup The configuration parameters group name.
* @param array $nestedParamsGroups Configuration group names that are included into configuration parameters group.
* This is needed for recursive merging of parameters.
* @param array $nestedEventsGroups Configuration group names that are included into events' configuration group.
* This is needed for reverse and recursive merge of events' configurations.
*
* @psalm-param list<string> $nestedParamsGroups
* @psalm-param list<string> $nestedEventsGroups
*/
public function __construct(
string $rootPath,
bool $debug,
string $paramsConfigGroup = 'params',
string $containerConfigGroup = 'web',
?string $bootstrapGroup = 'bootstrap-web',
?string $eventsGroup = 'events-web',
bool $debug = false,
bool $checkEvents = false,
?string $environment = null,
string $bootstrapGroup = 'bootstrap-web',
string $eventsGroup = 'events-web',
string $diGroup = 'di-web',
string $diProvidersGroup = 'di-providers-web',
string $diDelegatesGroup = 'di-delegates-web',
string $diTagsGroup = 'di-tags-web',
string $paramsGroup = 'params-web',
array $nestedParamsGroups = ['params'],
array $nestedEventsGroups = ['events'],
) {
parent::__construct($rootPath, $debug, $paramsConfigGroup, $containerConfigGroup, $environment);
$this->bootstrapGroup = $bootstrapGroup;
$this->eventsGroup = $eventsGroup;
parent::__construct(
$rootPath,
$debug,
$checkEvents,
$environment,
$bootstrapGroup,
$eventsGroup,
$diGroup,
$diProvidersGroup,
$diDelegatesGroup,
$diTagsGroup,
$paramsGroup,
$nestedParamsGroups,
$nestedEventsGroups,
);
}

/**
Expand Down
14 changes: 6 additions & 8 deletions tests/HttpApplicationRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public function testRun(): void

public function testRunWithoutBootstrapAndCheckEvents(): void
{
$runner = $this->runner
->withoutBootstrap()
->withoutCheckingEvents();
$runner = new HttpApplicationRunner(
rootPath: __DIR__ . '/Support',
debug: true,
checkEvents: false,
);

$this->expectOutputString('OK');

Expand Down Expand Up @@ -119,10 +121,6 @@ public function testRunWithFailureDuringProcess(): void

public function testImmutability(): void
{
$this->assertNotSame($this->runner, $this->runner->withBootstrap('bootstrap-web'));
$this->assertNotSame($this->runner, $this->runner->withoutBootstrap());
$this->assertNotSame($this->runner, $this->runner->withCheckingEvents('events-web'));
$this->assertNotSame($this->runner, $this->runner->withoutCheckingEvents());
$this->assertNotSame($this->runner, $this->runner->withConfig($this->createConfig()));
$this->assertNotSame($this->runner, $this->runner->withContainer($this->createContainer()));
$this->assertNotSame($this->runner, $this->runner->withTemporaryErrorHandler($this->createErrorHandler()));
Expand All @@ -137,7 +135,7 @@ private function createContainer(bool $throwException = false): ContainerInterfa

private function createConfig(): Config
{
return new Config(new ConfigPaths(__DIR__ . '/Support', 'config'));
return new Config(new ConfigPaths(__DIR__ . '/Support', 'config'), paramsGroup: 'params-web');
}

private function createDefinitions(bool $throwException): array
Expand Down
16 changes: 8 additions & 8 deletions tests/Support/config/.merge-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
// Do not edit. Content will be replaced.
return [
'/' => [
'params' => [
'params-web' => [
'/' => [
'params.php',
'params-web.php',
],
],
'web' => [
'di-web' => [
'/' => [
'web.php',
'di-web.php',
],
],
'events-web' => [
'/' => [
'events-web.php',
],
],
'providers-web' => [
'di-providers-web' => [
'/' => [
'providers-web.php',
'di-providers-web.php',
],
],
'delegates-web' => [
'di-delegates-web' => [
'/' => [
'delegates-web.php',
'di-delegates-web.php',
],
],
'bootstrap-web' => [
Expand Down
File renamed without changes.