Skip to content

Commit c3e51ee

Browse files
authored
Merge pull request #1607 from andrey-helldar/patch/2021-04-12/12-50
[9.x] Improving the project structure
2 parents 54048d1 + f9214fe commit c3e51ee

File tree

482 files changed

+109
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

482 files changed

+109
-108
lines changed

app/main/Application.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,31 @@ public function basePath(): string
2525

2626
public function sourcePath(string $filename = null): string
2727
{
28-
return $this->path('script/en/' . $this->cleanPath($filename));
28+
return $this->path('source/' . $this->cleanPath($filename));
2929
}
3030

31-
public function path(string $path = null): string
31+
public function localePath(string $locale = null): string
3232
{
33-
if ($value = $this->cleanPath($path)) {
34-
return $this->basePath() . '/' . $value;
35-
}
36-
37-
return $this->basePath();
33+
return $this->path('locales/' . $this->cleanPath($locale));
3834
}
3935

4036
public function excludePath(string $locale): string
4137
{
42-
return $this->path('excludes/' . $locale . '.php');
38+
return $this->path('excludes/' . $this->cleanPath($locale) . '.php');
4339
}
4440

4541
public function resourcePath(string $filename): string
4642
{
47-
return $this->path('app/resources/' . $filename);
43+
return $this->path('app/resources/' . $this->cleanPath($filename));
44+
}
45+
46+
public function path(string $path = null): string
47+
{
48+
if ($value = $this->cleanPath($path)) {
49+
return $this->basePath() . '/' . $value;
50+
}
51+
52+
return $this->basePath();
4853
}
4954

5055
public function cleanPath(string $path = null): ?string

app/main/Concerns/Contains.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace LaravelLang\Lang\Concerns;
44

5-
use Helldar\Support\Facades\Helpers\Str;
6-
75
trait Contains
86
{
97
protected function isJson(string $filename): bool
108
{
11-
return Str::endsWith($filename, '.json');
9+
return str_ends_with($filename, 'json');
10+
}
11+
12+
protected function isPhp(string $filename): bool
13+
{
14+
return ! $this->isJson($filename);
1215
}
1316

1417
protected function isValidation(string $filename): bool
1518
{
16-
return Str::startsWith($filename, 'validation');
19+
return str_starts_with($filename, 'validation');
1720
}
1821
}

app/main/Contracts/Application.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ public function basePath(): string;
1010

1111
public function sourcePath(string $filename = null): string;
1212

13-
public function path(string $path = null): string;
13+
public function localePath(string $locale = null): string;
1414

1515
public function excludePath(string $locale): string;
1616

1717
public function resourcePath(string $filename): string;
1818

19+
public function path(string $path = null): string;
20+
1921
public function cleanPath(string $path = null): ?string;
2022

2123
public function filesystem(Filesystem $filesystem): self;

app/main/Processors/Json.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
namespace LaravelLang\Lang\Processors;
44

5-
use Helldar\Support\Facades\Helpers\Filesystem\File;
5+
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
66

77
final class Json extends Processor
88
{
9-
protected string $target_path = 'json';
9+
protected string $target_path = 'locales';
1010

1111
public function run(): void
1212
{
1313
foreach ($this->locales() as $locale) {
14-
$target_path = $this->getTargetPath($locale);
14+
$target_path = $this->getTargetPath($locale . '/' . $locale . '.json');
1515

1616
$this->process($target_path, 'en.json', $locale);
1717
}
1818
}
1919

2020
protected function locales(): array
2121
{
22-
return File::names($this->getTargetPath());
22+
return Directory::names($this->getTargetPath());
2323
}
2424
}

app/main/Processors/Php.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
final class Php extends Processor
99
{
10-
protected string $target_path = 'src';
10+
protected string $target_path = 'locales';
1111

1212
public function run(): void
1313
{
@@ -22,7 +22,7 @@ public function run(): void
2222

2323
protected function files(string $locale): array
2424
{
25-
return File::names($this->getTargetPath($locale));
25+
return File::names($this->getTargetPath($locale), fn ($filename) => $this->isPhp($filename));
2626
}
2727

2828
protected function locales(): array

app/main/Processors/Referents.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Referents extends Processor
1414
{
1515
use Template;
1616

17-
protected string $target_path = 'src';
17+
protected string $target_path = 'locales';
1818

1919
public function run(): void
2020
{

app/main/Processors/Statuses/Processor.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Helldar\Support\Facades\Helpers\Arr;
66
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
77
use Helldar\Support\Facades\Helpers\Filesystem\File;
8-
use Helldar\Support\Facades\Helpers\Str;
98
use Helldar\Support\Facades\Tools\Sorter;
109
use LaravelLang\Lang\Concerns\Excludes;
1110
use LaravelLang\Lang\Concerns\Template;
@@ -90,11 +89,9 @@ protected function countMissing(string $locale): int
9089
return array_sum($items);
9190
}
9291

93-
protected function getLangPath(string $locale = null): string
92+
protected function getLocalePath(string $locale = null): string
9493
{
95-
$locale = $this->app->cleanPath($locale);
96-
97-
return $this->app->path('src/' . $locale);
94+
return $this->app->localePath($locale);
9895
}
9996

10097
protected function getFileBasename(string $filename): string
@@ -111,7 +108,7 @@ protected function getCorrectedFilename(string $filename, string $locale): strin
111108

112109
protected function locales(): array
113110
{
114-
return Directory::names($this->getLangPath());
111+
return Directory::names($this->getLocalePath());
115112
}
116113

117114
protected function files(): array
@@ -122,12 +119,12 @@ protected function files(): array
122119

123120
$files = File::names($this->getSourcePath());
124121

125-
return $this->source_files = Arr::sort($files, static function (string $a, string $b) {
122+
return $this->source_files = Arr::sort($files, function (string $a, string $b) {
126123
if ($a === $b) {
127124
return 0;
128125
}
129126

130-
if (Str::endsWith($a, '.json')) {
127+
if ($this->isJson($a)) {
131128
return 1;
132129
}
133130

@@ -139,9 +136,9 @@ protected function files(): array
139136

140137
protected function target(string $locale, string $filename): array
141138
{
142-
$path = $this->isJson($filename)
143-
? $this->app->path('json/' . $filename)
144-
: $this->app->path('src/' . $locale . '/' . $filename);
139+
$corrected = $this->getCorrectedFilename($filename, $locale);
140+
141+
$path = $this->getLocalePath($locale . '/' . $corrected);
145142

146143
return $this->load($path);
147144
}

app/main/Services/Compilers/Compiler.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace LaravelLang\Lang\Services\Compilers;
44

55
use Helldar\Support\Concerns\Makeable;
6-
use Helldar\Support\Facades\Helpers\Str;
6+
use LaravelLang\Lang\Concerns\Contains;
77
use LaravelLang\Lang\Concerns\Template;
88
use LaravelLang\Lang\Contracts\Application;
99
use LaravelLang\Lang\Contracts\Stringable;
1010

1111
abstract class Compiler implements Stringable
1212
{
13+
use Contains;
1314
use Makeable;
1415
use Template;
1516

@@ -26,9 +27,4 @@ public function items(array $items): self
2627

2728
return $this;
2829
}
29-
30-
protected function isJson(string $filename): bool
31-
{
32-
return Str::contains($filename, 'json');
33-
}
3430
}

app/tests/JsonTest.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
namespace Tests;
44

55
use Helldar\PrettyArray\Services\File as Pretty;
6-
use Helldar\Support\Facades\Helpers\Filesystem\File;
6+
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
77

88
final class JsonTest extends TestCase
99
{
10-
protected string $target_path = __DIR__ . '/../../json';
11-
1210
public function testJson(): void
1311
{
1412
$source = $this->source('en.json');
1513

16-
foreach ($this->files() as $file) {
17-
$path = $this->target_path . '/' . $file;
14+
foreach ($this->files() as $locale) {
15+
$path = $this->target_path . '/' . $locale . '/' . $locale . '.json';
1816

1917
$target = $this->load($path);
2018

@@ -24,7 +22,7 @@ public function testJson(): void
2422

2523
protected function files(): array
2624
{
27-
return File::names($this->target_path);
25+
return Directory::names($this->target_path);
2826
}
2927

3028
protected function load(string $path): array

app/tests/PhpTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
use Helldar\PrettyArray\Services\File as Pretty;
66
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
77
use Helldar\Support\Facades\Helpers\Filesystem\File;
8-
use Helldar\Support\Facades\Helpers\Str;
98

109
final class PhpTest extends TestCase
1110
{
12-
protected string $target_path = __DIR__ . '/../../src';
13-
1411
public function testPhp(): void
1512
{
1613
foreach ($this->files() as $filename) {
@@ -32,7 +29,7 @@ public function testPhp(): void
3229

3330
protected function files(): array
3431
{
35-
return File::names($this->source_path, static fn ($filename) => Str::endsWith($filename, '.php'));
32+
return File::names($this->source_path, static fn ($filename) => str_ends_with($filename, '.php'));
3633
}
3734

3835
protected function locales(): array

app/tests/StatusLocalesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class StatusLocalesTest extends TestCase
99
{
10-
protected string $source_path = __DIR__ . '/../../src';
10+
protected string $source_path = __DIR__ . '/../../locales';
1111

1212
protected string $target_path = __DIR__ . '/../../docs/statuses';
1313

app/tests/StatusTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
final class StatusTest extends TestCase
99
{
10-
protected string $target_path = __DIR__ . '/../../src';
10+
protected string $target_path = __DIR__ . '/../../locales';
1111

1212
protected string $status = __DIR__ . '/../../docs/status.md';
1313

app/tests/TestCase.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
use Helldar\PrettyArray\Services\File;
66
use Helldar\Support\Facades\Helpers\Arr;
7-
use Helldar\Support\Facades\Helpers\Str;
87
use PHPUnit\Framework\TestCase as BaseTestCase;
98
use Tests\Concerns\Messages;
109

1110
abstract class TestCase extends BaseTestCase
1211
{
1312
use Messages;
1413

15-
protected string $source_path = __DIR__ . '/../../script/en';
14+
protected string $source_path = __DIR__ . '/../../source';
1615

17-
protected string $target_path;
16+
protected string $target_path = __DIR__ . '/../../locales';
1817

1918
protected function source(string $filename): array
2019
{
@@ -39,7 +38,7 @@ protected function assertSee(string $path, string $content): void
3938
$file = File::make()->loadRaw($path);
4039

4140
$this->assertTrue(
42-
Str::contains($file, $content),
41+
str_contains($file, $content),
4342
$this->messageAssertSee($path, $content)
4443
);
4544
}
@@ -49,7 +48,7 @@ protected function assertDoesntSee(string $path, string $content): void
4948
$file = File::make()->loadRaw($path);
5049

5150
$this->assertFalse(
52-
Str::contains($file, $content),
51+
str_contains($file, $content),
5352
$this->messageAssertDoesntSee($path, $content)
5453
);
5554
}
@@ -61,11 +60,11 @@ protected function sort(array &$array): void
6160

6261
protected function isValidation(string $filename): bool
6362
{
64-
return Str::startsWith($filename, 'validation');
63+
return str_starts_with($filename, 'validation');
6564
}
6665

6766
protected function isInline(string $filename): bool
6867
{
69-
return Str::contains($filename, 'inline');
68+
return str_contains($filename, 'inline');
7069
}
7170
}

0 commit comments

Comments
 (0)