|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Information; |
|
6
|
|
|
|
|
7
|
|
|
class InformationWrapper implements InformationInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var array<string> */ |
|
10
|
|
|
private array $informations; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @param array<string> $informations |
|
14
|
|
|
*/ |
|
15
|
36 |
|
public function __construct(array $informations = []) |
|
16
|
|
|
{ |
|
17
|
36 |
|
$this->informations = $informations; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
16 |
|
public function addInformation(?string $information): InformationInterface |
|
21
|
|
|
{ |
|
22
|
16 |
|
if ($information !== null) { |
|
23
|
16 |
|
$this->informations[] = $information; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
16 |
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function addInformationf(string $information, ...$args): InformationInterface |
|
30
|
|
|
{ |
|
31
|
|
|
$this->addInformation(vsprintf( |
|
32
|
|
|
$information, |
|
33
|
|
|
$args |
|
34
|
|
|
)); |
|
35
|
|
|
|
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param array<string> $informations |
|
41
|
|
|
*/ |
|
42
|
7 |
|
public function addInformationArray(array $informations, bool $isHead = false): InformationWrapper |
|
43
|
|
|
{ |
|
44
|
7 |
|
if ($isHead) { |
|
45
|
1 |
|
$this->informations = array_merge($informations, $this->informations); |
|
46
|
|
|
} else { |
|
47
|
7 |
|
$this->informations = array_merge($this->informations, $informations); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
7 |
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
public function addInformationWrapper(?InformationWrapper $informations, bool $isHead = false): InformationWrapper |
|
54
|
|
|
{ |
|
55
|
2 |
|
if ($informations !== null) { |
|
56
|
2 |
|
$this->addInformationArray($informations->getInformations(), $isHead); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array<string> |
|
64
|
|
|
*/ |
|
65
|
29 |
|
public function getInformations(): array |
|
66
|
|
|
{ |
|
67
|
29 |
|
return $this->informations; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getInformationsAsString(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return implode(PHP_EOL, $this->getInformations()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function dumpTo(InformationInterface $informations): void |
|
76
|
|
|
{ |
|
77
|
|
|
array_walk( |
|
78
|
|
|
$this->informations, |
|
79
|
|
|
function (string $info) use ($informations): void { |
|
80
|
|
|
$informations->addInformation($info); |
|
81
|
|
|
} |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
4 |
|
public function isEmpty(): bool |
|
86
|
|
|
{ |
|
87
|
4 |
|
return empty($this->getInformations()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|