1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Services; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Contracts\Process; |
6
|
|
|
use Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException; |
7
|
|
|
use Helldar\LaravelLangPublisher\Services\Processing\DeleteJson; |
8
|
|
|
use Helldar\LaravelLangPublisher\Services\Processing\DeletePhp; |
9
|
|
|
use Helldar\LaravelLangPublisher\Services\Processing\PublishJson; |
10
|
|
|
use Helldar\LaravelLangPublisher\Services\Processing\PublishPhp; |
11
|
|
|
|
12
|
|
|
final class Localization |
13
|
|
|
{ |
14
|
|
|
/** @var array */ |
15
|
|
|
protected $result = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string $locale |
19
|
|
|
* @param bool $force |
20
|
|
|
* @param bool $json |
21
|
|
|
* |
22
|
|
|
* @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException |
23
|
|
|
* |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
54 |
|
public function publish(string $locale, bool $force = false, bool $json = false): array |
27
|
|
|
{ |
28
|
54 |
|
return $json |
29
|
30 |
|
? $this->process(PublishJson::class, $locale, $force) |
30
|
42 |
|
: $this->process(PublishPhp::class, $locale, $force); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $locale |
35
|
|
|
* @param bool $json |
36
|
|
|
* |
37
|
|
|
* @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
24 |
|
public function delete(string $locale, bool $json = false): array |
42
|
|
|
{ |
43
|
24 |
|
return $json |
44
|
12 |
|
? $this->process(DeleteJson::class, $locale) |
45
|
24 |
|
: $this->process(DeletePhp::class, $locale); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $classname |
50
|
|
|
* @param string $locale |
51
|
|
|
* @param bool $force |
52
|
|
|
* |
53
|
|
|
* @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException |
54
|
|
|
* |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
78 |
|
protected function process(string $classname, string $locale, bool $force = false) |
58
|
|
|
{ |
59
|
78 |
|
return $this->makeProcess($classname) |
60
|
78 |
|
->locale($locale) |
61
|
78 |
|
->force($force) |
62
|
78 |
|
->run(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $classname |
67
|
|
|
* |
68
|
|
|
* @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException |
69
|
|
|
* |
70
|
|
|
* @return Process |
71
|
|
|
*/ |
72
|
78 |
|
protected function makeProcess(string $classname): Process |
73
|
|
|
{ |
74
|
78 |
|
if (! is_subclass_of($classname, Process::class)) { |
75
|
|
|
throw new NoProcessInstanceException($classname); |
76
|
|
|
} |
77
|
|
|
|
78
|
78 |
|
return app($classname); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|