Skip to content

Commit 46fe6f6

Browse files
authored
Remove yiisoft/i18n dependency + Refactor ApplicationParameters (#363)
1 parent 0568953 commit 46fe6f6

7 files changed

Lines changed: 15 additions & 56 deletions

File tree

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"yiisoft/error-handler": "^4.1",
5959
"yiisoft/html": "^3.11",
6060
"yiisoft/http": "^1.2",
61-
"yiisoft/i18n": "^1.2.1",
6261
"yiisoft/injector": "^1.2",
6362
"yiisoft/log": "^2.1.1",
6463
"yiisoft/log-target-file": "^3.0",

config/common/di/application-parameters.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
return [
1010
ApplicationParameters::class => [
11-
'class' => ApplicationParameters::class,
12-
'charset()' => [$params['app']['charset']],
13-
'name()' => [$params['app']['name']],
11+
'__construct()' => [
12+
'name' => $params['app']['name'],
13+
'charset' => $params['app']['charset'],
14+
'locale' => $params['app']['locale'],
15+
],
1416
],
1517
];

config/common/di/i18n.php

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

resources/views/layout/main.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
use App\Asset\AppAsset;
66
use Yiisoft\Html\Html;
7-
use Yiisoft\I18n\Locale;
87

98
/**
109
* @var App\ApplicationParameters $applicationParameters
1110
* @var Yiisoft\Aliases\Aliases $aliases
1211
* @var Yiisoft\Assets\AssetManager $assetManager
1312
* @var string $content
1413
* @var string|null $csrf
15-
* @var Locale $locale
1614
* @var Yiisoft\View\WebView $this
1715
* @var Yiisoft\Router\CurrentRoute $currentRoute
1816
* @var Yiisoft\Router\UrlGeneratorInterface $urlGenerator
@@ -28,9 +26,9 @@
2826

2927
$this->beginPage()
3028
?><!DOCTYPE html>
31-
<html lang="<?= Html::encode($locale->language()) ?>">
29+
<html lang="<?= Html::encode($applicationParameters->locale) ?>">
3230
<head>
33-
<meta charset="<?= Html::encode($applicationParameters->getCharset()) ?>">
31+
<meta charset="<?= Html::encode($applicationParameters->charset) ?>">
3432
<meta http-equiv="X-UA-Compatible" content="IE=edge">
3533
<meta name="viewport" content="width=device-width, initial-scale=1">
3634
<title><?= Html::encode($this->getTitle()) ?></title>
@@ -77,7 +75,7 @@
7775
<div class="footer">
7876
<div class="footer_copyright">
7977
<a href="https://www.yiiframework.com/" target="_blank" rel="noopener">
80-
© <?= date('Y') ?> <?= Html::encode($applicationParameters->getName()) ?>
78+
© <?= date('Y') ?> <?= Html::encode($applicationParameters->name) ?>
8179
</a>
8280
</div>
8381
<div class="footer_icons">

resources/views/site/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Yiisoft\Translator\TranslatorInterface;
1313
use Yiisoft\View\WebView;
1414

15-
$this->setTitle($applicationParameters->getName());
15+
$this->setTitle($applicationParameters->name);
1616
?>
1717

1818
<div class="text-center">

src/ApplicationParameters.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,11 @@
44

55
namespace App;
66

7-
final class ApplicationParameters
7+
final readonly class ApplicationParameters
88
{
9-
private string $charset = 'UTF-8';
10-
private string $name = 'My Project';
11-
12-
public function getCharset(): string
13-
{
14-
return $this->charset;
15-
}
16-
17-
public function getName(): string
18-
{
19-
return $this->name;
20-
}
21-
22-
public function charset(string $value): self
23-
{
24-
$new = clone $this;
25-
$new->charset = $value;
26-
return $new;
27-
}
28-
29-
public function name(string $value): self
30-
{
31-
$new = clone $this;
32-
$new->name = $value;
33-
return $new;
34-
}
9+
public function __construct(
10+
public string $name = 'My Project',
11+
public string $charset = 'UTF-8',
12+
public string $locale = 'en',
13+
) {}
3514
}

src/ViewInjection/LayoutViewInjection.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Yiisoft\Aliases\Aliases;
88
use Yiisoft\Assets\AssetManager;
9-
use Yiisoft\I18n\Locale;
109
use Yiisoft\Router\CurrentRoute;
1110
use Yiisoft\Yii\View\Renderer\LayoutParametersInjectionInterface;
1211

@@ -15,7 +14,6 @@
1514
public function __construct(
1615
private Aliases $aliases,
1716
private AssetManager $assetManager,
18-
private Locale $locale,
1917
private CurrentRoute $currentRoute,
2018
) {}
2119

@@ -24,7 +22,6 @@ public function getLayoutParameters(): array
2422
return [
2523
'aliases' => $this->aliases,
2624
'assetManager' => $this->assetManager,
27-
'locale' => $this->locale,
2825
'currentRoute' => $this->currentRoute,
2926
];
3027
}

0 commit comments

Comments
 (0)