|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverLeague\LogViewer\Helper; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class LogFormatter formats the array to a readable unordered list |
|
7
|
|
|
* |
|
8
|
|
|
* @package SilverLeague\LogViewer\Helper |
|
9
|
|
|
* |
|
10
|
|
|
* @author Simon Erkelens <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class LogFormatter |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array for future reference |
|
17
|
|
|
*/ |
|
18
|
|
|
private static $icons = [ |
|
|
|
|
|
|
19
|
|
|
'DEBUG' => 'info-cirled', |
|
20
|
|
|
'INFO' => 'help-circled', |
|
21
|
|
|
'NOTICE' => 'help-plus-circled', |
|
22
|
|
|
'WARNING' => 'info-circled', |
|
23
|
|
|
'ERROR' => 'cancel-circled', |
|
24
|
|
|
'CRITICAL' => 'cancel-circled', |
|
25
|
|
|
'ALERT' => 'help-circled', |
|
26
|
|
|
'EMERGENCY' => 'cancel-circled' |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Recursive method, will call itself if a sub element is an array |
|
31
|
|
|
* @param array $data |
|
32
|
|
|
* @param bool $first start with an opening bracket? if true, skip (counterintuitive, but naming) |
|
33
|
|
|
* @return string formatted <ul><li> of the array; |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function entryToUl($data, $first = true) |
|
36
|
|
|
{ |
|
37
|
|
|
$out = $first ? '<span style="color: #007700">[</span>' : ''; |
|
38
|
|
|
$out .= '<ul style="margin-bottom: 0">'; |
|
39
|
|
|
foreach ($data as $key => $arrayItem) { |
|
40
|
|
|
if (!is_array($arrayItem)) { |
|
41
|
|
|
$out .= '<li class="list-unstyled">' . |
|
42
|
|
|
'<span style="color: #0000BB">' . $key . '</span>' . |
|
43
|
|
|
'<span style="color: #007700">: </span>' . |
|
44
|
|
|
'<span style="color: #DD0000">' . $arrayItem . '</span>'. |
|
45
|
|
|
'</li>'; |
|
46
|
|
|
} else { |
|
47
|
|
|
$out .= '<li class="list-unstyled">' . |
|
48
|
|
|
'<span style="color: #0000BB">' . $key . '</span>' . |
|
49
|
|
|
'<span style="color: #007700">: </span>' . |
|
50
|
|
|
self::entryToUl($arrayItem) . |
|
51
|
|
|
'</li>'; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
$out .= '</ul>'; |
|
55
|
|
|
$out .= $first ? '<span style="color: #007700">]</span>' : ''; |
|
56
|
|
|
|
|
57
|
|
|
return $out; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.