1 | <?php |
||
16 | abstract class AbstractTable implements TableContract |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Properties |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** @var array */ |
||
24 | private $header = []; |
||
25 | |||
26 | /** @var array */ |
||
27 | private $rows = []; |
||
28 | |||
29 | /** @var array */ |
||
30 | private $footer = []; |
||
31 | |||
32 | /** @var \Arcanedev\LogViewer\Contracts\Utilities\LogLevels */ |
||
33 | protected $levels; |
||
34 | |||
35 | /** @var string|null */ |
||
36 | protected $locale; |
||
37 | |||
38 | /** @var array */ |
||
39 | private $data = []; |
||
40 | |||
41 | /* ----------------------------------------------------------------- |
||
42 | | Constructor |
||
43 | | ----------------------------------------------------------------- |
||
44 | */ |
||
45 | |||
46 | /** |
||
47 | * Create a table instance. |
||
48 | * |
||
49 | * @param array $data |
||
50 | * @param \Arcanedev\LogViewer\Contracts\Utilities\LogLevels $levels |
||
51 | * @param string|null $locale |
||
52 | */ |
||
53 | 78 | public function __construct(array $data, LogLevelsContract $levels, $locale = null) |
|
60 | |||
61 | /* ----------------------------------------------------------------- |
||
62 | | Getters & Setters |
||
63 | | ----------------------------------------------------------------- |
||
64 | */ |
||
65 | |||
66 | /** |
||
67 | * Set LogLevels instance. |
||
68 | * |
||
69 | * @param \Arcanedev\LogViewer\Contracts\Utilities\LogLevels $levels |
||
70 | * |
||
71 | * @return self |
||
72 | */ |
||
73 | 78 | protected function setLevels(LogLevelsContract $levels) |
|
79 | |||
80 | /** |
||
81 | * Set table locale. |
||
82 | * |
||
83 | * @param string|null $locale |
||
84 | * |
||
85 | * @return self |
||
86 | */ |
||
87 | 78 | protected function setLocale($locale) |
|
97 | |||
98 | /** |
||
99 | * Get table header. |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | 42 | public function header() |
|
107 | |||
108 | /** |
||
109 | * Get table rows. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 36 | public function rows() |
|
117 | |||
118 | /** |
||
119 | * Get table footer. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | 48 | public function footer() |
|
127 | |||
128 | /** |
||
129 | * Get raw data. |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 6 | public function data() |
|
137 | |||
138 | /** |
||
139 | * Set table data. |
||
140 | * |
||
141 | * @param array $data |
||
142 | * |
||
143 | * @return self |
||
144 | */ |
||
145 | 78 | private function setData(array $data) |
|
151 | |||
152 | /* ----------------------------------------------------------------- |
||
153 | | Main Methods |
||
154 | | ----------------------------------------------------------------- |
||
155 | */ |
||
156 | |||
157 | /** |
||
158 | * Prepare the table. |
||
159 | */ |
||
160 | 78 | private function init() |
|
166 | |||
167 | /** |
||
168 | * Prepare table header. |
||
169 | * |
||
170 | * @param array $data |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | abstract protected function prepareHeader(array $data); |
||
175 | |||
176 | /** |
||
177 | * Prepare table rows. |
||
178 | * |
||
179 | * @param array $data |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | abstract protected function prepareRows(array $data); |
||
184 | |||
185 | /** |
||
186 | * Prepare table footer. |
||
187 | * |
||
188 | * @param array $data |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | abstract protected function prepareFooter(array $data); |
||
193 | |||
194 | /* ----------------------------------------------------------------- |
||
195 | | Other Methods |
||
196 | | ----------------------------------------------------------------- |
||
197 | */ |
||
198 | |||
199 | /** |
||
200 | * Get log level color. |
||
201 | * |
||
202 | * @param string $level |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | 18 | protected function color($level) |
|
210 | } |
||
211 |