Skip to content

Commit a98109b

Browse files
Fixed some small aspects
1 parent f0d20be commit a98109b

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/generic/BasicInitConfig.php

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

33
namespace spaf\simputils\generic;
44

5+
use spaf\simputils\attributes\DebugHide;
56
use spaf\simputils\attributes\markers\Shortcut;
67
use spaf\simputils\attributes\Property;
78
use spaf\simputils\DT;
@@ -58,10 +59,15 @@ abstract class BasicInitConfig extends SimpleObject {
5859
public ?string $code_root = null;
5960
public ?string $working_dir = null;
6061
public array|Box $disable_init_for = [];
62+
63+
#[DebugHide]
6164
protected null|string $_l10n_name = null;
65+
#[DebugHide]
6266
protected mixed $_l10n = null;
6367

68+
#[DebugHide]
6469
protected array $_successful_init_blocks = [];
70+
#[DebugHide]
6571
protected bool $_is_already_setup = false;
6672

6773
#[Property('default_tz')]
@@ -76,11 +82,6 @@ protected function setDefaultTimeZone(string|DateTimeZone $tz) {
7682
DT::setDefaultTimeZone($tz);
7783
}
7884

79-
#[Property('l10n_name')]
80-
protected function getL10nName(): mixed {
81-
return $this->_l10n_name;
82-
}
83-
8485
#[Property('l10n')]
8586
protected function getL10n(): mixed {
8687
return $this->_l10n;
@@ -93,11 +94,11 @@ protected function setL10n(null|string|L10n $val): void {
9394
$this->_l10n_name = $val; // @codeCoverageIgnore
9495
} else {
9596
if (Str::is($val)) {
96-
$this->_l10n_name = $val;
9797

9898
$class = PHP::redef(L10n::class);
9999
$l10n_name = Str::upper($val);
100100
$path = FS::path(PHP::frameworkDir(), 'data', 'l10n', "{$l10n_name}.json");
101+
/** @var L10n $val */
101102
$val = $class::createFrom($path);
102103

103104
$custom_file = FS::file(
@@ -108,6 +109,7 @@ protected function setL10n(null|string|L10n $val): void {
108109
$val, 'setup', $custom_file->content ?? [] // @codeCoverageIgnore
109110
); // @codeCoverageIgnore
110111
}
112+
$val->name = $l10n_name;
111113
}
112114

113115
/** @var L10n $val */

src/models/L10n.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22

33
namespace spaf\simputils\models;
44

5+
use spaf\simputils\attributes\DebugHide;
6+
use spaf\simputils\attributes\Property;
57
use spaf\simputils\DT;
68
use spaf\simputils\generic\SimpleObject;
79
use spaf\simputils\PHP;
810
use spaf\simputils\traits\RedefinableComponentTrait;
911

12+
/**
13+
* @property $name Name of the locale (basically-read only, can be set only once)
14+
*/
1015
class L10n extends SimpleObject {
1116
use RedefinableComponentTrait;
1217

18+
#[DebugHide]
19+
protected ?string $_name = null;
20+
21+
#[Property('name')]
22+
protected function setName(string $val) {
23+
if (empty($this->_name)) {
24+
$this->_name = $val;
25+
}
26+
}
27+
28+
#[Property('name')]
29+
protected function getName(): ?string {
30+
return $this->_name;
31+
}
32+
1333
public static $is_auto_setup = true;
1434

1535
protected $DateTime = [
@@ -22,7 +42,6 @@ class L10n extends SimpleObject {
2242
protected $DataUnit = [
2343
'translations' => []
2444
];
25-
2645
/**
2746
* Apply those settings to other classes
2847
*

tests/general/InitConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function initBlock(BasicInitConfig $config) {
2727
class InitConfigTest extends TestCase {
2828

2929
/**
30+
* @covers \spaf\simputils\models\L10n
3031
* @runInSeparateProcess
3132
* @return void
3233
*/
@@ -37,7 +38,7 @@ function testBasics() {
3738
new CustomInitCodeBlock(),
3839
]);
3940
$this->assertInstanceOf(L10n::class, $config->l10n);
40-
$this->assertEquals('RU', $config->l10n_name);
41+
$this->assertEquals('RU', $config->l10n->name);
4142
$this->assertEquals('Asia/Novosibirsk', $config->default_tz);
4243

4344
}

0 commit comments

Comments
 (0)