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