1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Services\Filesystem; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Facades\Path; |
6
|
|
|
use Helldar\PrettyArray\Services\File as Pretty; |
7
|
|
|
use Helldar\Support\Facades\Helpers\Arr; |
8
|
|
|
|
9
|
|
|
final class Json extends Filesystem |
10
|
28 |
|
{ |
11
|
|
|
public function load(string $path, string $filename): array |
12
|
28 |
|
{ |
13
|
|
|
$this->log('Loading the contents of the file:', $path); |
14
|
28 |
|
|
15
|
28 |
|
if ($this->doesntExists($path)) { |
16
|
|
|
$this->log('File not found:', $path); |
17
|
28 |
|
|
18
|
|
|
return []; |
19
|
|
|
} |
20
|
28 |
|
|
21
|
|
|
dd($path, $filename); |
22
|
28 |
|
|
23
|
|
|
$keys = $this->loadKeys($path); |
24
|
28 |
|
$source = $this->loadTranslations($filename); |
25
|
|
|
|
26
|
28 |
|
return Arr::only($source, $keys); |
27
|
|
|
} |
28
|
|
|
|
29
|
28 |
|
public function store(string $path, array $content) |
30
|
|
|
{ |
31
|
28 |
|
$this->log('Saving an array to a file:', $path); |
32
|
|
|
|
33
|
28 |
|
Arr::storeAsJson($path, $content, false, JSON_UNESCAPED_UNICODE ^ JSON_PRETTY_PRINT); |
34
|
28 |
|
} |
35
|
|
|
|
36
|
|
|
protected function loadKeys(string $path): array |
37
|
|
|
{ |
38
|
|
|
$this->log('Loading keys from a file:', $path); |
39
|
|
|
|
40
|
|
|
return $this->loadFile($path); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function loadTranslations(): array |
44
|
|
|
{ |
45
|
|
|
dd( |
46
|
|
|
'aaaa', |
47
|
|
|
Path::sourceFull('laravel-lang/lang', 'en', 'en.json'), |
48
|
|
|
); |
|
|
|
|
49
|
|
|
// $this->log('Loading translations from a file:', $path); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function loadFile(string $path): array |
53
|
|
|
{ |
54
|
|
|
$this->log('Loading data from a file:', $path); |
55
|
|
|
|
56
|
|
|
$content = Pretty::make()->loadRaw($path); |
57
|
|
|
|
58
|
|
|
$items = json_decode($content, true); |
59
|
|
|
|
60
|
|
|
return $this->correctValues($items); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: