1 | <?php namespace Arcanedev\LogViewer\Tables; |
||
12 | abstract class AbstractTable implements TableContract |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** @var array */ |
||
19 | private $header = []; |
||
20 | |||
21 | /** @var array */ |
||
22 | private $rows = []; |
||
23 | |||
24 | /** @var array */ |
||
25 | private $footer = []; |
||
26 | |||
27 | /** @var \Arcanedev\LogViewer\Contracts\Utilities\LogLevels */ |
||
28 | protected $levels; |
||
29 | |||
30 | /** @var string|null */ |
||
31 | protected $locale; |
||
32 | |||
33 | /** @var array */ |
||
34 | private $data = []; |
||
35 | |||
36 | /* ------------------------------------------------------------------------------------------------ |
||
37 | | Constructor |
||
38 | | ------------------------------------------------------------------------------------------------ |
||
39 | */ |
||
40 | /** |
||
41 | * Create a table instance. |
||
42 | * |
||
43 | * @param array $data |
||
44 | * @param \Arcanedev\LogViewer\Contracts\Utilities\LogLevels $levels |
||
45 | * @param string|null $locale |
||
46 | */ |
||
47 | public function __construct(array $data, LogLevelsContract $levels, $locale = null) |
||
54 | |||
55 | /* ------------------------------------------------------------------------------------------------ |
||
56 | | Getters & Setters |
||
57 | | ------------------------------------------------------------------------------------------------ |
||
58 | */ |
||
59 | /** |
||
60 | * Set LogLevels instance. |
||
61 | * |
||
62 | * @param \Arcanedev\LogViewer\Contracts\Utilities\LogLevels $levels |
||
63 | * |
||
64 | * @return \Arcanedev\LogViewer\Tables\AbstractTable |
||
65 | */ |
||
66 | protected function setLevels(LogLevelsContract $levels) |
||
72 | |||
73 | /** |
||
74 | * Set table locale. |
||
75 | * |
||
76 | * @param string|null $locale |
||
77 | * |
||
78 | * @return \Arcanedev\LogViewer\Tables\AbstractTable |
||
79 | */ |
||
80 | protected function setLocale($locale) |
||
90 | |||
91 | /** |
||
92 | * Get table header. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function header() |
||
100 | |||
101 | /** |
||
102 | * Get table rows. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function rows() |
||
110 | |||
111 | /** |
||
112 | * Get table footer. |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | public function footer() |
||
120 | |||
121 | /** |
||
122 | * Get raw data. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | public function data() |
||
130 | |||
131 | /** |
||
132 | * Set table data. |
||
133 | * |
||
134 | * @param array $data |
||
135 | * |
||
136 | * @return self |
||
137 | */ |
||
138 | private function setData(array $data) |
||
144 | |||
145 | /* ------------------------------------------------------------------------------------------------ |
||
146 | | Main Functions |
||
147 | | ------------------------------------------------------------------------------------------------ |
||
148 | */ |
||
149 | /** |
||
150 | * Prepare the table. |
||
151 | */ |
||
152 | private function init() |
||
158 | |||
159 | /** |
||
160 | * Prepare table header. |
||
161 | * |
||
162 | * @param array $data |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | abstract protected function prepareHeader(array $data); |
||
167 | |||
168 | /** |
||
169 | * Prepare table rows. |
||
170 | * |
||
171 | * @param array $data |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | abstract protected function prepareRows(array $data); |
||
176 | |||
177 | /** |
||
178 | * Prepare table footer. |
||
179 | * |
||
180 | * @param array $data |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | abstract protected function prepareFooter(array $data); |
||
185 | |||
186 | /* ------------------------------------------------------------------------------------------------ |
||
187 | | Other Functions |
||
188 | | ------------------------------------------------------------------------------------------------ |
||
189 | */ |
||
190 | /** |
||
191 | * Translate. |
||
192 | * |
||
193 | * @param string $key |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | protected function translate($key) |
||
204 | |||
205 | /** |
||
206 | * Get log level color. |
||
207 | * |
||
208 | * @param string $level |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | protected function color($level) |
||
216 | } |
||
217 |