1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author stev leibelt <[email protected]> |
4
|
|
|
* @since 2017-04-11 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder; |
8
|
|
|
|
9
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\Detail; |
10
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\Information; |
11
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\Scoreboard; |
12
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\Statistic; |
13
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Parser\DetailListOfLineParser; |
14
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Parser\InformationListOfLineParser; |
15
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Parser\ScoreboardListOfLineParser; |
16
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Parser\StatisticListOfLineParser; |
17
|
|
|
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Storage\StorageInterface; |
18
|
|
|
use RuntimeException; |
19
|
|
|
|
20
|
|
|
class ParserBuilder implements BuilderInterface |
21
|
|
|
{ |
22
|
|
|
/** @var DetailListOfLineParser */ |
23
|
|
|
private $detailListOfLineParser; |
24
|
|
|
|
25
|
|
|
/** @var InformationListOfLineParser */ |
26
|
|
|
private $informationListOfLineParser; |
27
|
|
|
|
28
|
|
|
/** @var null|Information */ |
29
|
|
|
private $informationOrNull; |
30
|
|
|
|
31
|
|
|
/** @var null|Detail[] */ |
32
|
|
|
private $listOfDetailOrNull; |
33
|
|
|
|
34
|
|
|
/** @var ScoreboardListOfLineParser */ |
35
|
|
|
private $scoreboardListOfLineParser; |
36
|
|
|
|
37
|
|
|
/** @var null|Scoreboard */ |
38
|
|
|
private $scoreboardOrNull; |
39
|
|
|
|
40
|
|
|
/** @var StatisticListOfLineParser */ |
41
|
|
|
private $statisticListOfLineParser; |
42
|
|
|
|
43
|
|
|
/** @var null|Statistic */ |
44
|
|
|
private $statisticOrNull; |
45
|
|
|
|
46
|
|
|
/** @var StorageInterface */ |
47
|
|
|
private $storage; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* ParserBuilder constructor. |
51
|
|
|
* |
52
|
|
|
* @param DetailListOfLineParser $detailListOfLineParser |
53
|
|
|
* @param InformationListOfLineParser $informationListOfLineParser |
54
|
|
|
* @param ScoreboardListOfLineParser $scoreboardListOfLineParser |
55
|
|
|
* @param StatisticListOfLineParser $statisticListOfLineParser |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
DetailListOfLineParser $detailListOfLineParser, |
59
|
|
|
InformationListOfLineParser $informationListOfLineParser, |
60
|
|
|
ScoreboardListOfLineParser $scoreboardListOfLineParser, |
61
|
|
|
StatisticListOfLineParser $statisticListOfLineParser |
62
|
|
|
) { |
63
|
|
|
$this->detailListOfLineParser = $detailListOfLineParser; |
64
|
|
|
$this->informationListOfLineParser = $informationListOfLineParser; |
65
|
|
|
$this->scoreboardListOfLineParser = $scoreboardListOfLineParser; |
66
|
|
|
$this->statisticListOfLineParser = $statisticListOfLineParser; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param StorageInterface $storage |
71
|
|
|
*/ |
72
|
|
|
public function setStorageUpfront(StorageInterface $storage) |
73
|
|
|
{ |
74
|
|
|
$this->storage = $storage; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @throws RuntimeException |
79
|
|
|
*/ |
80
|
|
|
public function build() |
81
|
|
|
{ |
82
|
|
|
//begin of dependencies |
83
|
|
|
$detailListOfLineParser = $this->detailListOfLineParser; |
84
|
|
|
$informationListOfLineParser = $this->informationListOfLineParser; |
85
|
|
|
$informationOrNull = null; |
86
|
|
|
$listOfDetailOrNull = null; |
87
|
|
|
$scoreboardListOfLineParser = $this->scoreboardListOfLineParser; |
88
|
|
|
$scoreboardOrNull = null; |
89
|
|
|
$statisticListOfLineParser = $this->statisticListOfLineParser; |
90
|
|
|
$statisticOrNull = null; |
91
|
|
|
$storage = $this->storage; |
92
|
|
|
//end of dependencies |
93
|
|
|
|
94
|
|
|
//begin of business logic |
95
|
|
|
if ($storage->hasListOfDetail()) { |
96
|
|
|
$listOfDetailOrNull = $detailListOfLineParser->parse( |
97
|
|
|
$storage->getListOfDetail() |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ($storage->hasListOfInformation()) { |
102
|
|
|
$informationOrNull = $informationListOfLineParser->parse( |
103
|
|
|
$storage->getListOfInformation() |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if ($storage->hasListOfScoreboard()) { |
108
|
|
|
$scoreboardOrNull = $scoreboardListOfLineParser->parse( |
109
|
|
|
$storage->getListOfScoreboard() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($storage->hasListOfStatistic()) { |
114
|
|
|
$statisticOrNull = $statisticListOfLineParser->parse( |
115
|
|
|
$storage->getListOfStatistic() |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$this->informationOrNull = $informationOrNull; |
120
|
|
|
$this->listOfDetailOrNull = $listOfDetailOrNull; |
121
|
|
|
$this->scoreboardOrNull = $scoreboardOrNull; |
122
|
|
|
$this->statisticOrNull = $statisticOrNull; |
123
|
|
|
//end of business logic |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return null|Information |
128
|
|
|
*/ |
129
|
|
|
public function andGetInformationOrNullAfterwards() |
130
|
|
|
{ |
131
|
|
|
return $this->informationOrNull; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return null|Detail[] |
136
|
|
|
*/ |
137
|
|
|
public function andGetListOfDetailOrNullAfterwards() |
138
|
|
|
{ |
139
|
|
|
return $this->listOfDetailOrNull; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return null|Scoreboard |
144
|
|
|
*/ |
145
|
|
|
public function andGetScoreboardOrNullAfterwards() |
146
|
|
|
{ |
147
|
|
|
return $this->scoreboardOrNull; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return null|Statistic |
152
|
|
|
*/ |
153
|
|
|
public function andGetStatisticOrNullAfterwards() |
154
|
|
|
{ |
155
|
|
|
return $this->statisticOrNull; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|