Total Complexity | 11 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class Translation implements AsyncBrokerInterface |
||
9 | { |
||
10 | |||
11 | protected $locales = []; |
||
12 | protected $words = []; |
||
13 | |||
14 | public function __construct(VocabTerm $vocab = null) |
||
15 | { |
||
16 | $this->locales = [ |
||
17 | app()->getLocale(), |
||
|
|||
18 | config('app.locale'), |
||
19 | config('app.fallback_locale'), |
||
20 | config('app.faker_locale'), |
||
21 | ]; |
||
22 | $this->words = $vocab ? [$vocab->id] : $this->words; |
||
23 | } |
||
24 | |||
25 | public function targetLocales($locales = []) |
||
26 | { |
||
27 | $this->locales = array_unique( |
||
28 | array_merge( |
||
29 | $this->locales, |
||
30 | $locales |
||
31 | ) |
||
32 | ); |
||
33 | return $this; |
||
34 | } |
||
35 | |||
36 | public function words($words = null) |
||
37 | { |
||
38 | |||
39 | $words = $words ? VocabTerm::whereIn('term', (array)words)->pluck('id')->toarray() : $words; |
||
40 | $this->words = $words ?? ($this->words ?: VocabTerm::pluck('id')->toArray()); |
||
41 | return $this; |
||
42 | } |
||
43 | |||
44 | |||
45 | |||
46 | public function handle() |
||
47 | { |
||
48 | foreach ($this->words as $word) { |
||
49 | $this->translation(VocabTerm::find($word)); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | private function translation(VocabTerm $word) |
||
66 | } |
||
67 | } |
||
68 |