1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Services\Filesystem; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Facades\Config; |
6
|
|
|
use Helldar\PrettyArray\Services\File as Pretty; |
7
|
|
|
use Helldar\PrettyArray\Services\Formatter; |
8
|
|
|
|
9
|
|
|
final class Php extends Filesystem |
10
|
|
|
{ |
11
|
11 |
|
public function load(string $path): array |
12
|
|
|
{ |
13
|
11 |
|
if ($this->doesntExists($path)) { |
14
|
11 |
|
$this->log('File not found: ' . $path); |
15
|
|
|
|
16
|
11 |
|
return []; |
17
|
|
|
} |
18
|
|
|
|
19
|
11 |
|
$this->log('Loading data from a file: ' . $path); |
20
|
|
|
|
21
|
11 |
|
$items = Pretty::make()->load($path); |
22
|
|
|
|
23
|
11 |
|
return $this->correctValues($items); |
24
|
|
|
} |
25
|
|
|
|
26
|
11 |
|
public function store(string $path, array $content) |
27
|
|
|
{ |
28
|
11 |
|
$this->log('Saving an array to a file: ' . $path); |
29
|
|
|
|
30
|
11 |
|
$service = Formatter::make(); |
31
|
|
|
|
32
|
11 |
|
$this->setFormatterCase($service); |
33
|
11 |
|
$this->setFormatterAlignment($service); |
34
|
11 |
|
$this->setFormatterKeyToString($service); |
35
|
|
|
|
36
|
11 |
|
Pretty::make($service->raw($content))->store($path); |
37
|
11 |
|
} |
38
|
|
|
|
39
|
11 |
|
protected function isAlignment(): bool |
40
|
|
|
{ |
41
|
11 |
|
return Config::hasAlignment(); |
42
|
|
|
} |
43
|
|
|
|
44
|
11 |
|
protected function setFormatterCase(Formatter $formatter): void |
45
|
|
|
{ |
46
|
11 |
|
$this->log('Setting the key conversion label.'); |
47
|
|
|
|
48
|
11 |
|
$formatter->setCase(Config::getCase()); |
49
|
11 |
|
} |
50
|
|
|
|
51
|
11 |
|
protected function setFormatterAlignment(Formatter $formatter): void |
52
|
|
|
{ |
53
|
11 |
|
$this->log('Setting the alignment label of values.'); |
54
|
|
|
|
55
|
11 |
|
if ($this->isAlignment()) { |
56
|
11 |
|
$formatter->setEqualsAlign(); |
57
|
|
|
} |
58
|
11 |
|
} |
59
|
|
|
|
60
|
11 |
|
protected function setFormatterKeyToString(Formatter $formatter): void |
61
|
|
|
{ |
62
|
11 |
|
$this->log('Setting the label for converting numeric keys to string...'); |
63
|
|
|
|
64
|
11 |
|
$formatter->setKeyAsString(); |
65
|
11 |
|
} |
66
|
|
|
} |
67
|
|
|
|