1
|
|
|
<?php namespace Arcanedev\LogViewer\Utilities; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LogViewer\Contracts\Utilities\LogStyler as LogStylerContract; |
4
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigContract; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class LogStyler |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\LogViewer\Utilities |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class LogStyler implements LogStylerContract |
13
|
|
|
{ |
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
15
|
|
|
| Properties |
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
17
|
|
|
*/ |
18
|
|
|
/** |
19
|
|
|
* The config repository instance. |
20
|
|
|
* |
21
|
|
|
* @var \Illuminate\Contracts\Config\Repository |
22
|
|
|
*/ |
23
|
|
|
protected $config; |
24
|
|
|
|
25
|
|
|
/* ------------------------------------------------------------------------------------------------ |
26
|
|
|
| Constructor |
27
|
|
|
| ------------------------------------------------------------------------------------------------ |
28
|
|
|
*/ |
29
|
|
|
/** |
30
|
|
|
* Create a new instance. |
31
|
|
|
* |
32
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config |
33
|
|
|
*/ |
34
|
63 |
|
public function __construct(ConfigContract $config) |
35
|
|
|
{ |
36
|
63 |
|
$this->config = $config; |
37
|
63 |
|
} |
38
|
|
|
|
39
|
|
|
/* ------------------------------------------------------------------------------------------------ |
40
|
|
|
| Getters & Setters |
41
|
|
|
| ------------------------------------------------------------------------------------------------ |
42
|
|
|
*/ |
43
|
|
|
/** |
44
|
|
|
* Get config. |
45
|
|
|
* |
46
|
|
|
* @param string $key |
47
|
|
|
* @param mixed $default |
48
|
|
|
* |
49
|
|
|
* @return mixed |
50
|
|
|
*/ |
51
|
57 |
|
private function get($key, $default = null) |
52
|
|
|
{ |
53
|
57 |
|
return $this->config->get("log-viewer.$key", $default); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/* ------------------------------------------------------------------------------------------------ |
57
|
|
|
| Main Functions |
58
|
|
|
| ------------------------------------------------------------------------------------------------ |
59
|
|
|
*/ |
60
|
|
|
/** |
61
|
|
|
* Make level icon. |
62
|
|
|
* |
63
|
|
|
* @param string $level |
64
|
|
|
* @param string|null $default |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
39 |
|
public function icon($level, $default = null) |
69
|
|
|
{ |
70
|
39 |
|
return '<i class="'.$this->get("icons.$level", $default).'"></i>'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get level color. |
75
|
|
|
* |
76
|
|
|
* @param string $level |
77
|
|
|
* @param string|null $default |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
27 |
|
public function color($level, $default = null) |
82
|
|
|
{ |
83
|
27 |
|
return $this->get("colors.levels.$level", $default); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get strings to highlight. |
88
|
|
|
* |
89
|
|
|
* @param array $default |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
9 |
|
public function toHighlight(array $default = []) |
94
|
|
|
{ |
95
|
9 |
|
return $this->get("highlight", $default); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|