1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelLang\Entities; |
6
|
|
|
|
7
|
|
|
use Arcanedev\LaravelLang\Contracts\Entities\Locale as LocaleContract; |
8
|
|
|
use Illuminate\Support\{Arr, Str}; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Locale |
12
|
|
|
* |
13
|
|
|
* @package Arcanedev\LaravelLang\Entities |
14
|
|
|
* @author ARCANEDEV <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class Locale implements LocaleContract |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Properties |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $key = ''; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $path = ''; |
28
|
|
|
|
29
|
|
|
/** @var array */ |
30
|
|
|
private $files = []; |
31
|
|
|
|
32
|
|
|
/* ----------------------------------------------------------------- |
33
|
|
|
| Constructor |
34
|
|
|
| ----------------------------------------------------------------- |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Locale constructor. |
39
|
|
|
* |
40
|
|
|
* @param string $key |
41
|
|
|
* @param string $path |
42
|
|
|
* @param array $files |
43
|
|
|
*/ |
44
|
88 |
|
public function __construct(string $key, string $path, array $files = []) |
45
|
|
|
{ |
46
|
88 |
|
$this->key = $key; |
47
|
88 |
|
$this->path = $path; |
48
|
88 |
|
$this->files = $files; |
49
|
88 |
|
} |
50
|
|
|
|
51
|
|
|
/* ----------------------------------------------------------------- |
52
|
|
|
| Getters & Setters |
53
|
|
|
| ----------------------------------------------------------------- |
54
|
|
|
*/ |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the locale key. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
88 |
|
public function getKey(): string |
62
|
|
|
{ |
63
|
88 |
|
return $this->key; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the locale translations path. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
36 |
|
public function getPath(): string |
72
|
|
|
{ |
73
|
36 |
|
return $this->path; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get locale translations. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
8 |
|
public function getTranslations(): array |
82
|
|
|
{ |
83
|
8 |
|
$translations = array_map(function ($file) { |
84
|
8 |
|
return $file['content']; |
85
|
8 |
|
}, $this->files); |
86
|
|
|
|
87
|
8 |
|
return Arr::dot($translations); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/* ----------------------------------------------------------------- |
91
|
|
|
| Main Methods |
92
|
|
|
| ----------------------------------------------------------------- |
93
|
|
|
*/ |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Merge translations. |
97
|
|
|
* |
98
|
|
|
* @param \Arcanedev\LaravelLang\Contracts\Entities\Locale|null $locale |
99
|
|
|
* @param array $ignored |
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
4 |
|
public function mergeTranslations(LocaleContract $locale = null, array $ignored = []): array |
104
|
|
|
{ |
105
|
4 |
|
$merged = []; |
106
|
4 |
|
$translations = array_merge( |
107
|
4 |
|
is_null($locale) ? [] : $locale->getTranslations(), |
108
|
4 |
|
$this->getTranslations() |
109
|
|
|
); |
110
|
|
|
|
111
|
4 |
|
foreach ($translations as $key => $trans) { |
112
|
4 |
|
if ( ! Str::startsWith($key, $ignored)) { |
113
|
4 |
|
$merged[$key] = $trans; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
4 |
|
return $merged; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: