1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the "andrey-helldar/laravel-lang-publisher" project. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @author Andrey Helldar <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @copyright 2021 Andrey Helldar |
12
|
|
|
* |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @see https://github.com/andrey-helldar/laravel-lang-publisher |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Helldar\LaravelLangPublisher\Console; |
21
|
|
|
|
22
|
|
|
use Helldar\Contracts\LangPublisher\Processor; |
23
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Optionable; |
24
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Paths; |
25
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Config; |
26
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales; |
27
|
|
|
use Helldar\LaravelLangPublisher\Facades\Support\Filesystem; |
28
|
|
|
use Helldar\LaravelLangPublisher\Facades\Support\Filter; |
29
|
|
|
use Illuminate\Console\Command; |
30
|
|
|
|
31
|
|
|
abstract class Base extends Command |
32
|
|
|
{ |
33
|
|
|
use Optionable; |
34
|
|
|
use Paths; |
35
|
|
|
|
36
|
|
|
protected $processor; |
37
|
|
|
|
38
|
|
|
public function handle() |
39
|
|
|
{ |
40
|
|
|
$this->collecting(); |
41
|
|
|
|
42
|
|
|
$this->store($this->filter()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function collecting(): void |
46
|
|
|
{ |
47
|
|
|
foreach ($this->plugins() as $provider) { |
48
|
|
|
$this->info('Collecting ' . get_class($provider) . '...'); |
49
|
|
|
|
50
|
|
|
$this->getProcessor()->provider($provider); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function filter(): array |
55
|
|
|
{ |
56
|
|
|
$this->info('Filtering...'); |
57
|
|
|
|
58
|
|
|
$source = $this->getProcessor()->source(); |
59
|
|
|
$translated = $this->getProcessor()->translated(); |
60
|
|
|
|
61
|
|
|
return Filter::keys($source) |
62
|
|
|
->translated($translated) |
63
|
|
|
->get(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function store(array $items): void |
67
|
|
|
{ |
68
|
|
|
$this->info('Storing...'); |
69
|
|
|
|
70
|
|
|
foreach ($items as $filename => $values) { |
71
|
|
|
$path = $this->resourcesPath($filename); |
72
|
|
|
|
73
|
|
|
Filesystem::store($path, $values); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return \Helldar\Contracts\LangPublisher\Provider[] |
79
|
|
|
*/ |
80
|
|
|
protected function plugins(): array |
81
|
|
|
{ |
82
|
|
|
return Config::plugins(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function getProcessor(): Processor |
86
|
|
|
{ |
87
|
|
|
if (! is_string($this->processor)) { |
88
|
|
|
return $this->processor; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$locales = $this->targetLocales(); |
92
|
|
|
$force = $this->hasForce(); |
93
|
|
|
|
94
|
|
|
return $this->processor = new $this->processor($locales, $force); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function targetLocales(): array |
98
|
|
|
{ |
99
|
|
|
return Locales::installed(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|