Skip to content

Commit 964089b

Browse files
authored
Introduce ApplicationParams (#232)
1 parent cf7744d commit 964089b

9 files changed

Lines changed: 65 additions & 27 deletions

File tree

config/common/application.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'name' => 'My Project',
7+
'version' => '1.0',
8+
];

config/common/di/application.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\ApplicationParams;
6+
7+
/** @var array $params */
8+
9+
return [
10+
ApplicationParams::class => [
11+
'__construct()' => [
12+
'name' => $params['application']['name'],
13+
'version' => $params['application']['version'],
14+
],
15+
],
16+
];

config/common/params.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
declare(strict_types=1);
44

55
return [
6-
'supportEmail' => 'support@example.com',
6+
'application' => require __DIR__ . '/application.php',
77

88
'yiisoft/aliases' => [
99
'aliases' => require __DIR__ . '/aliases.php',
1010
],
11-
12-
'yiisoft/view' => [
13-
'basePath' => '@views',
14-
'parameters' => [],
15-
],
1611
];

config/common/routes.php

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

33
declare(strict_types=1);
44

5-
use App\Controller\IndexController;
5+
use App\Controller\IndexAction;
66
use Yiisoft\Router\Route;
77

88
/**
@@ -11,6 +11,6 @@
1111

1212
return [
1313
Route::get('/')
14-
->action([IndexController::class, 'index'])
14+
->action(IndexAction::class)
1515
->name('app/index'),
1616
];

src/ApplicationParams.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App;
6+
7+
final readonly class ApplicationParams
8+
{
9+
public function __construct(
10+
public string $name = 'My Project',
11+
public string $version = '1.0',
12+
) {}
13+
}

src/Controller/IndexAction.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller;
6+
7+
use App\ApplicationParams;
8+
use Psr\Http\Message\ResponseInterface;
9+
use Yiisoft\DataResponse\DataResponseFactoryInterface;
10+
11+
final class IndexAction
12+
{
13+
public function __invoke(
14+
DataResponseFactoryInterface $responseFactory,
15+
ApplicationParams $applicationParams,
16+
): ResponseInterface {
17+
return $responseFactory->createResponse([
18+
'name' => $applicationParams->name,
19+
'version' => $applicationParams->version,
20+
]);
21+
}
22+
}

src/Controller/IndexController.php

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

tests/Acceptance/SiteCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function getHome(AcceptanceTester $I): void
2020
'error_message' => '',
2121
'error_code' => null,
2222
'data' => [
23-
'version' => '3.0',
24-
'author' => 'yiisoft',
23+
'name' => 'My Project',
24+
'version' => '1.0',
2525
],
2626
],
2727
);

tests/Functional/InfoControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testGetIndex()
2929
'status' => 'success',
3030
'error_message' => '',
3131
'error_code' => null,
32-
'data' => ['version' => '3.0', 'author' => 'yiisoft'],
32+
'data' => ['name' => 'My Project', 'version' => '1.0'],
3333
],
3434
json_decode($output, true),
3535
);

0 commit comments

Comments
 (0)