|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Support; |
|
4
|
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Contains; |
|
6
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Keyable; |
|
7
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Logger; |
|
8
|
|
|
use Helldar\LaravelLangPublisher\Constants\Status; |
|
9
|
|
|
use Helldar\Support\Facades\Helpers\Str; |
|
10
|
|
|
|
|
11
|
|
|
final class Message |
|
12
|
|
|
{ |
|
13
|
|
|
use Contains; |
|
14
|
|
|
use Keyable; |
|
15
|
|
|
use Logger; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
protected $styles = [ |
|
18
|
|
|
Status::COPIED => 'fg=green', |
|
19
|
|
|
Status::RESET => 'fg=magenta', |
|
20
|
|
|
Status::SKIPPED => 'fg=default', |
|
21
|
|
|
Status::DELETED => 'fg=red', |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
protected $locales_length = 0; |
|
25
|
|
|
|
|
26
|
|
|
protected $files_length = 0; |
|
27
|
|
|
|
|
28
|
|
|
protected $package; |
|
29
|
|
|
|
|
30
|
|
|
protected $locale; |
|
31
|
|
|
|
|
32
|
|
|
protected $filename; |
|
33
|
|
|
|
|
34
|
|
|
protected $status; |
|
35
|
|
|
|
|
36
|
|
|
public function same(): self |
|
37
|
|
|
{ |
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function package(string $package): self |
|
42
|
|
|
{ |
|
43
|
|
|
$this->package = $package; |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function length(int $locales, int $files): self |
|
49
|
|
|
{ |
|
50
|
|
|
$this->locales_length = abs($locales) + 3; |
|
51
|
|
|
$this->files_length = abs($files) + 4; |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function locale(string $locale): self |
|
57
|
|
|
{ |
|
58
|
|
|
$this->locale = $locale; |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function filename(string $filename): self |
|
64
|
|
|
{ |
|
65
|
|
|
$this->filename = $this->key($filename); |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function status(string $status): self |
|
71
|
|
|
{ |
|
72
|
|
|
$this->status = $status; |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function get(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getPackage() . $this->getLocale() . $this->getFilename() . $this->getStatus(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function pad(string $value, int $length): string |
|
83
|
|
|
{ |
|
84
|
|
|
return str_pad($value, $length); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
protected function getPackage(): string |
|
88
|
|
|
{ |
|
89
|
|
|
$length = Str::length($this->package); |
|
90
|
|
|
|
|
91
|
|
|
$value = $this->pad($this->package, $length + 1); |
|
92
|
|
|
|
|
93
|
|
|
return $this->format($value, 'fg=#a6a6a6'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function getLocale(): string |
|
97
|
|
|
{ |
|
98
|
|
|
$value = $this->pad("[$this->locale]", $this->locales_length); |
|
99
|
|
|
|
|
100
|
|
|
return $this->format($value, 'comment'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function getFilename(): string |
|
104
|
|
|
{ |
|
105
|
|
|
$value = $this->pad($this->filename . '...', $this->files_length); |
|
106
|
|
|
|
|
107
|
|
|
return $this->format($value); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
protected function getStatus(): string |
|
111
|
|
|
{ |
|
112
|
|
|
$style = $this->styles[$this->status]; |
|
113
|
|
|
|
|
114
|
|
|
return $this->format($this->status, $style); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
protected function format(string $value, string $style = null): string |
|
118
|
|
|
{ |
|
119
|
|
|
return $style ? "<$style>$value</>" : $value; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|