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
|
|
|
|
10
|
|
|
final class Message |
11
|
|
|
{ |
12
|
|
|
use Contains; |
13
|
|
|
use Keyable; |
14
|
|
|
use Logger; |
|
|
|
|
15
|
|
|
|
16
|
|
|
protected $styles = [ |
17
|
|
|
Status::COPIED => 'fg=green', |
18
|
|
|
Status::RESET => 'fg=magenta', |
19
|
|
|
Status::SKIPPED => 'fg=default', |
20
|
|
|
Status::DELETED => 'fg=red', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
protected $locales_length = 0; |
24
|
|
|
|
25
|
|
|
protected $files_length = 0; |
26
|
|
|
|
27
|
|
|
protected $locale; |
28
|
|
|
|
29
|
|
|
protected $filename; |
30
|
|
|
|
31
|
|
|
protected $status; |
32
|
|
|
|
33
|
12 |
|
public function same(): self |
34
|
|
|
{ |
35
|
12 |
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
12 |
|
public function length(int $locales, int $files): self |
39
|
|
|
{ |
40
|
12 |
|
$this->locales_length = abs($locales) + 3; |
41
|
12 |
|
$this->files_length = abs($files) + 4; |
42
|
|
|
|
43
|
12 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
12 |
|
public function locale(string $locale): self |
47
|
|
|
{ |
48
|
12 |
|
$this->locale = $locale; |
49
|
|
|
|
50
|
12 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
12 |
|
public function filename(string $filename): self |
54
|
|
|
{ |
55
|
12 |
|
$this->filename = $this->key($filename); |
56
|
|
|
|
57
|
12 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
12 |
|
public function status(string $status): self |
61
|
|
|
{ |
62
|
12 |
|
$this->status = $status; |
63
|
|
|
|
64
|
12 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
12 |
|
public function get(): string |
68
|
|
|
{ |
69
|
12 |
|
return $this->getLocale() . $this->getFilename() . $this->getStatus(); |
70
|
|
|
} |
71
|
|
|
|
72
|
12 |
|
protected function pad(string $value, int $length): string |
73
|
|
|
{ |
74
|
12 |
|
return str_pad($value, $length); |
75
|
|
|
} |
76
|
|
|
|
77
|
12 |
|
protected function getLocale(): string |
78
|
|
|
{ |
79
|
12 |
|
$value = $this->pad("[$this->locale]", $this->locales_length); |
80
|
|
|
|
81
|
12 |
|
return $this->format($value, 'comment'); |
82
|
|
|
} |
83
|
|
|
|
84
|
12 |
|
protected function getFilename(): string |
85
|
|
|
{ |
86
|
12 |
|
$value = $this->pad($this->filename . '...', $this->files_length); |
87
|
|
|
|
88
|
12 |
|
return $this->format($value); |
89
|
|
|
} |
90
|
|
|
|
91
|
12 |
|
protected function getStatus(): string |
92
|
|
|
{ |
93
|
12 |
|
$style = $this->styles[$this->status]; |
94
|
|
|
|
95
|
12 |
|
return $this->format($this->status, $style); |
96
|
|
|
} |
97
|
|
|
|
98
|
12 |
|
protected function format(string $value, string $style = null): string |
99
|
|
|
{ |
100
|
12 |
|
return $style ? "<$style>$value</>" : $value; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|