1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Console; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Contracts\Localizationable; |
6
|
|
|
use Helldar\LaravelLangPublisher\Services\Localization; |
7
|
|
|
use Helldar\LaravelLangPublisher\Support\Result; |
8
|
|
|
use Helldar\LaravelLangPublisher\Traits\Containable; |
9
|
|
|
use Helldar\LaravelLangPublisher\Traits\Containers\Pathable; |
10
|
|
|
use Helldar\LaravelLangPublisher\Traits\Containers\Processable; |
11
|
|
|
use Illuminate\Console\Command; |
12
|
|
|
|
13
|
|
|
abstract class BaseCommand extends Command |
14
|
|
|
{ |
15
|
|
|
use Containable; |
16
|
|
|
use Processable; |
17
|
|
|
use Pathable; |
18
|
|
|
|
19
|
|
|
/** @var \Helldar\LaravelLangPublisher\Support\Result */ |
20
|
|
|
protected $result; |
21
|
|
|
|
22
|
36 |
|
public function __construct(Result $result) |
23
|
|
|
{ |
24
|
36 |
|
parent::__construct(); |
25
|
|
|
|
26
|
36 |
|
$this->result = $result->setOutput($this); |
27
|
36 |
|
} |
28
|
|
|
|
29
|
12 |
|
protected function locales(): array |
30
|
|
|
{ |
31
|
12 |
|
return (array) $this->argument('locales'); |
32
|
|
|
} |
33
|
|
|
|
34
|
12 |
|
protected function isForce(): bool |
35
|
|
|
{ |
36
|
12 |
|
return (bool) $this->option('force'); |
37
|
|
|
} |
38
|
|
|
|
39
|
12 |
|
protected function wantsJson(): bool |
40
|
|
|
{ |
41
|
12 |
|
return (bool) $this->option('json'); |
42
|
|
|
} |
43
|
|
|
|
44
|
12 |
|
protected function setProcessor(string $php, string $json): void |
45
|
|
|
{ |
46
|
12 |
|
$this->processor = $this->wantsJson() ? $json : $php; |
47
|
12 |
|
} |
48
|
|
|
|
49
|
12 |
|
protected function exec(array $locales): void |
50
|
|
|
{ |
51
|
12 |
|
foreach ($this->getLocales($locales) as $locale) { |
52
|
12 |
|
$this->result->merge( |
53
|
12 |
|
$this->localization() |
54
|
12 |
|
->setPath($this->getPath()) |
55
|
12 |
|
->setProcessor($this->getProcessor()) |
56
|
12 |
|
->run($locale, $this->isForce()) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
12 |
|
protected function getLocales(array $locales): array |
62
|
|
|
{ |
63
|
12 |
|
return $this->locales() === ['*'] |
64
|
|
|
? $locales |
65
|
12 |
|
: $this->locales(); |
66
|
|
|
} |
67
|
|
|
|
68
|
12 |
|
protected function localization(): Localizationable |
69
|
|
|
{ |
70
|
12 |
|
return app(Localization::class); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|