1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the "andrey-helldar/laravel-lang-publisher" project. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @author Andrey Helldar <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @copyright 2021 Andrey Helldar |
12
|
|
|
* |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @see https://github.com/andrey-helldar/laravel-lang-publisher |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Helldar\LaravelLangPublisher\Support\Filesystem; |
21
|
|
|
|
22
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Config; |
23
|
|
|
use Helldar\PrettyArray\Services\File as Pretty; |
24
|
|
|
use Helldar\PrettyArray\Services\Formatter; |
25
|
|
|
|
26
|
|
|
class Php extends Base |
27
|
|
|
{ |
28
|
|
|
public function load(string $path) |
29
|
|
|
{ |
30
|
|
|
if ($this->doesntExists($path)) { |
31
|
|
|
return []; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$items = Pretty::make()->load($path); |
35
|
|
|
|
36
|
|
|
return $this->correct($items); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function store(string $path, $content): string |
40
|
|
|
{ |
41
|
|
|
$service = $this->formatter(); |
42
|
|
|
|
43
|
|
|
Pretty::make($service->raw($content))->store($path); |
44
|
|
|
|
45
|
|
|
return $path; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function formatter(): Formatter |
49
|
|
|
{ |
50
|
|
|
$formatter = Formatter::make(); |
51
|
|
|
|
52
|
|
|
$this->setCase($formatter); |
53
|
|
|
$this->setAlignment($formatter); |
54
|
|
|
$this->setKeyToString($formatter); |
55
|
|
|
|
56
|
|
|
return $formatter; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function setCase(Formatter $formatter): void |
60
|
|
|
{ |
61
|
|
|
$formatter->setCase( |
62
|
|
|
$this->getCase() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function setAlignment(Formatter $formatter): void |
67
|
|
|
{ |
68
|
|
|
if ($this->hasAlignment()) { |
69
|
|
|
$formatter->setEqualsAlign(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function setKeyToString(Formatter $formatter): void |
74
|
|
|
{ |
75
|
|
|
$formatter->setKeyAsString(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function getCase(): int |
79
|
|
|
{ |
80
|
|
|
return Config::case(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function hasAlignment(): bool |
84
|
|
|
{ |
85
|
|
|
return Config::hasAlignment(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|