1 | <?php |
||||
2 | |||||
3 | namespace EasyPanel\Services; |
||||
4 | |||||
5 | use Illuminate\Support\Facades\File; |
||||
6 | use Illuminate\Support\Str; |
||||
7 | |||||
8 | class LangService |
||||
9 | { |
||||
10 | public static function getLanguages() |
||||
11 | { |
||||
12 | $files = collect(static::getFiles()); |
||||
13 | |||||
14 | return $files->mapWithKeys(function ($file, $key){ |
||||
0 ignored issues
–
show
|
|||||
15 | preg_match('/(\w+)_panel\.json/i', $file, $m); |
||||
16 | $key = "$m[1]_panel"; |
||||
17 | $value = Str::upper($m[1]); |
||||
18 | return [$key => $value]; |
||||
19 | })->toArray(); |
||||
20 | } |
||||
21 | |||||
22 | public static function updateAll($texts) |
||||
23 | { |
||||
24 | foreach (static::getFiles() as $file) { |
||||
25 | $decodedFile = json_decode(File::get($file), 1); |
||||
26 | foreach ($texts as $key => $text) { |
||||
27 | if (array_key_exists($key, $decodedFile)){ |
||||
28 | unset($texts[$text]); |
||||
29 | } |
||||
30 | } |
||||
31 | $array = array_merge($decodedFile, $texts); |
||||
32 | File::put($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); |
||||
33 | } |
||||
34 | } |
||||
35 | |||||
36 | public static function getFiles() |
||||
37 | { |
||||
38 | return File::glob(app()->langPath().DIRECTORY_SEPARATOR.'*_panel.json'); |
||||
0 ignored issues
–
show
The method
langPath() does not exist on Illuminate\Container\Container . Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
39 | } |
||||
40 | |||||
41 | public static function getTexts($lang) |
||||
42 | { |
||||
43 | return json_decode(static::getContent($lang), true); |
||||
44 | } |
||||
45 | |||||
46 | public static function updateLanguage($lang, $texts) |
||||
47 | { |
||||
48 | $file = static::getContent($lang); |
||||
49 | |||||
50 | $decodedFile = json_decode($file, 1); |
||||
51 | |||||
52 | $array = array_merge($decodedFile, $texts); |
||||
53 | |||||
54 | File::put(static::getPath($lang), json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); |
||||
55 | } |
||||
56 | |||||
57 | public static function getContent($lang) |
||||
58 | { |
||||
59 | return File::get(static::getPath($lang)); |
||||
60 | } |
||||
61 | |||||
62 | public static function getPath($lang) |
||||
63 | { |
||||
64 | return app()->langPath().DIRECTORY_SEPARATOR."{$lang}.json"; |
||||
65 | } |
||||
66 | } |
||||
67 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.