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\Facades\Helpers\Config; |
25
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales; |
26
|
|
|
use Illuminate\Console\Command; |
27
|
|
|
|
28
|
|
|
abstract class Base extends Command |
29
|
|
|
{ |
30
|
|
|
use Optionable; |
31
|
|
|
|
32
|
|
|
protected $processor; |
33
|
|
|
|
34
|
|
|
public function handle() |
35
|
|
|
{ |
36
|
|
|
$this->collecting(); |
37
|
|
|
$this->store(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function collecting(): void |
41
|
|
|
{ |
42
|
|
|
foreach ($this->plugins() as $provider) { |
43
|
|
|
$this->info('Collecting ' . get_class($provider) . '...'); |
44
|
|
|
|
45
|
|
|
$this->getProcessor()->provider($provider); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function store(): void |
50
|
|
|
{ |
51
|
|
|
$this->info('Storing...'); |
52
|
|
|
|
53
|
|
|
$this->getProcessor()->store(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return \Helldar\Contracts\LangPublisher\Provider[] |
58
|
|
|
*/ |
59
|
|
|
protected function plugins(): array |
60
|
|
|
{ |
61
|
|
|
return Config::plugins(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function getProcessor(): Processor |
65
|
|
|
{ |
66
|
|
|
if (! empty($this->processor)) { |
67
|
|
|
return $this->processor; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** @var Processor $processor */ |
71
|
|
|
$processor = new $this->processor(); |
72
|
|
|
|
73
|
|
|
return $this->processor = $processor |
74
|
|
|
->locales($this->targetLocales()) |
75
|
|
|
->hasForce($this->hasForce()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function targetLocales(): array |
79
|
|
|
{ |
80
|
|
|
return Locales::installed(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|