Skip to content

Commit feec14d

Browse files
authored
Improve application configuration (#229)
1 parent a2f6437 commit feec14d

File tree

8 files changed

+59
-73
lines changed

8 files changed

+59
-73
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"yiisoft/error-handler": "^4.1",
5353
"yiisoft/http": "^1.2",
5454
"yiisoft/hydrator": "^1.6",
55-
"yiisoft/injector": "^1.2",
5655
"yiisoft/input-http": "^1.0.1",
5756
"yiisoft/log": "^2.1.1",
5857
"yiisoft/log-target-file": "^3.0",
@@ -106,7 +105,7 @@
106105
"branch-alias": {
107106
"dev-master": "1.0.x-dev"
108107
},
109-
"config-plugin-file": "configuration.php"
108+
"config-plugin-file": "config/configuration.php"
110109
},
111110
"config": {
112111
"sort-packages": true,

config/common/aliases.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'@root' => dirname(__DIR__, 2),
7+
'@assets' => '@public/assets',
8+
'@assetsUrl' => '@baseUrl/assets',
9+
'@baseUrl' => '/',
10+
'@data' => '@root/data',
11+
'@messages' => '@resources/messages',
12+
'@public' => '@root/public',
13+
'@resources' => '@root/resources',
14+
'@runtime' => '@root/runtime',
15+
'@src' => '@root/src',
16+
'@tests' => '@root/tests',
17+
'@views' => '@root/views',
18+
'@vendor' => '@root/vendor',
19+
];

config/common/params.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,7 @@
66
'supportEmail' => 'support@example.com',
77

88
'yiisoft/aliases' => [
9-
'aliases' => [
10-
'@root' => dirname(__DIR__, 2),
11-
'@assets' => '@public/assets',
12-
'@assetsUrl' => '@baseUrl/assets',
13-
'@baseUrl' => '/',
14-
'@data' => '@root/data',
15-
'@messages' => '@resources/messages',
16-
'@public' => '@root/public',
17-
'@resources' => '@root/resources',
18-
'@runtime' => '@root/runtime',
19-
'@src' => '@root/src',
20-
'@tests' => '@root/tests',
21-
'@views' => '@root/views',
22-
'@vendor' => '@root/vendor',
23-
],
9+
'aliases' => require __DIR__ . '/aliases.php',
2410
],
2511

2612
'yiisoft/router-fastroute' => [
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
declare(strict_types=1);
44

5+
use App\Environment;
6+
7+
// NOTE: After making changes in this file, run `composer yii-config-rebuild` to update the merge plan.
58
return [
69
'config-plugin' => [
710
'params' => 'common/params.php',
@@ -27,10 +30,7 @@
2730
'di-providers-web' => '$di-providers',
2831
'events' => [],
2932
'events-console' => '$events',
30-
'events-web' => [
31-
'$events',
32-
'web/events.php',
33-
],
33+
'events-web' => '$events',
3434
'bootstrap' => [],
3535
'bootstrap-console' => '$bootstrap',
3636
'bootstrap-web' => '$bootstrap',
@@ -39,19 +39,19 @@
3939
],
4040
],
4141
'config-plugin-environments' => [
42-
'dev' => [
42+
Environment::DEV => [
4343
'params' => [
4444
'environments/dev/params.php',
4545
],
4646
],
47-
'prod' => [
47+
Environment::TEST => [
4848
'params' => [
49-
'environments/prod/params.php',
49+
'environments/test/params.php',
5050
],
5151
],
52-
'test' => [
52+
Environment::PROD => [
5353
'params' => [
54-
'environments/test/params.php',
54+
'environments/prod/params.php',
5555
],
5656
],
5757
],

config/web/di/application.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@
55
use App\Http\NotFoundHandler;
66
use Yiisoft\Definitions\DynamicReference;
77
use Yiisoft\Definitions\Reference;
8-
use Yiisoft\Injector\Injector;
8+
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
9+
use Yiisoft\Input\Http\HydratorAttributeParametersResolver;
10+
use Yiisoft\Input\Http\RequestInputParametersResolver;
11+
use Yiisoft\Middleware\Dispatcher\CompositeParametersResolver;
912
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher;
13+
use Yiisoft\Middleware\Dispatcher\ParametersResolverInterface;
14+
use Yiisoft\RequestProvider\RequestCatcherMiddleware;
15+
use Yiisoft\Router\Middleware\Router;
16+
use Yiisoft\Yii\Http\Application;
17+
use Yiisoft\Yii\Middleware\Subfolder;
1018

1119
/** @var array $params */
1220

1321
return [
14-
Yiisoft\Yii\Http\Application::class => [
22+
Application::class => [
1523
'__construct()' => [
16-
'dispatcher' => DynamicReference::to(static function (Injector $injector) use ($params) {
17-
return $injector->make(MiddlewareDispatcher::class)
18-
->withMiddlewares($params['middlewares']);
19-
}),
24+
'dispatcher' => DynamicReference::to([
25+
'class' => MiddlewareDispatcher::class,
26+
'withMiddlewares()' => [
27+
[
28+
RequestCatcherMiddleware::class,
29+
ErrorCatcher::class,
30+
Subfolder::class,
31+
Router::class,
32+
],
33+
],
34+
]),
2035
'fallbackHandler' => Reference::to(NotFoundHandler::class),
2136
],
2237
],
38+
39+
ParametersResolverInterface::class => [
40+
'class' => CompositeParametersResolver::class,
41+
'__construct()' => [
42+
Reference::to(HydratorAttributeParametersResolver::class),
43+
Reference::to(RequestInputParametersResolver::class),
44+
],
45+
],
2346
];

config/web/di/middleware-dispatcher.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

config/web/events.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/web/params.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
6-
use Yiisoft\RequestProvider\RequestCatcherMiddleware;
7-
use Yiisoft\Router\Middleware\Router;
8-
use Yiisoft\Yii\Middleware\Subfolder;
9-
105
return [
116
'yiisoft/input-http' => [
127
'requestInputParametersResolver' => [
138
'throwInputValidationException' => true,
149
],
1510
],
16-
17-
'middlewares' => [
18-
RequestCatcherMiddleware::class,
19-
ErrorCatcher::class,
20-
Subfolder::class,
21-
Router::class,
22-
],
2311
];

0 commit comments

Comments
 (0)