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