|
1
|
|
|
<?php namespace Arcanedev\LogViewer\Utilities; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LogViewer\Contracts\LogMenuInterface; |
|
4
|
|
|
use Arcanedev\LogViewer\Contracts\LogStylerInterface; |
|
5
|
|
|
use Arcanedev\LogViewer\Entities\Log; |
|
6
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class LogMenu |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanedev\LogViewer\Utilities |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class LogMenu implements LogMenuInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
| Properties |
|
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
19
|
|
|
*/ |
|
20
|
|
|
/** |
|
21
|
|
|
* The config repository instance. |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Illuminate\Contracts\Config\Repository |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $config; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The log styler instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @var \Arcanedev\LogViewer\Contracts\LogStylerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $styler; |
|
33
|
|
|
|
|
34
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
35
|
|
|
| Constructor |
|
36
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
37
|
|
|
*/ |
|
38
|
|
|
/** |
|
39
|
|
|
* Create the LogMenu instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config |
|
42
|
|
|
* @param \Arcanedev\LogViewer\Contracts\LogStylerInterface $styler |
|
43
|
|
|
*/ |
|
44
|
27 |
|
public function __construct(Repository $config, LogStylerInterface $styler) |
|
45
|
|
|
{ |
|
46
|
27 |
|
$this->setConfig($config); |
|
47
|
27 |
|
$this->setLogStyler($styler); |
|
48
|
27 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
51
|
|
|
| Getters & Setters |
|
52
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
53
|
|
|
*/ |
|
54
|
|
|
/** |
|
55
|
|
|
* Set the config instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config |
|
58
|
|
|
* |
|
59
|
|
|
* @return self |
|
60
|
|
|
*/ |
|
61
|
27 |
|
public function setConfig(Repository $config) |
|
62
|
|
|
{ |
|
63
|
27 |
|
$this->config = $config; |
|
64
|
|
|
|
|
65
|
27 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set the log styler instance. |
|
70
|
|
|
* |
|
71
|
|
|
* @param \Arcanedev\LogViewer\Contracts\LogStylerInterface $styler |
|
72
|
|
|
* |
|
73
|
|
|
* @return self |
|
74
|
|
|
*/ |
|
75
|
27 |
|
public function setLogStyler(LogStylerInterface $styler) |
|
76
|
|
|
{ |
|
77
|
27 |
|
$this->styler = $styler; |
|
78
|
|
|
|
|
79
|
27 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
83
|
|
|
| Main Functions |
|
84
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
85
|
|
|
*/ |
|
86
|
|
|
/** |
|
87
|
|
|
* Make log menu. |
|
88
|
|
|
* |
|
89
|
|
|
* @param \Arcanedev\LogViewer\Entities\Log $log |
|
90
|
|
|
* @param bool $trans |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
24 |
|
public function make(Log $log, $trans = true) |
|
95
|
|
|
{ |
|
96
|
24 |
|
$items = []; |
|
97
|
24 |
|
$route = $this->config('menu.filter-route'); |
|
98
|
|
|
|
|
99
|
24 |
|
foreach($log->tree($trans) as $level => $item) { |
|
100
|
24 |
|
$items[$level] = array_merge($item, [ |
|
101
|
24 |
|
'url' => route($route, [$log->date, $level]), |
|
102
|
24 |
|
'icon' => $this->isIconsEnabled() ? $this->styler->icon($level) : '', |
|
103
|
24 |
|
]); |
|
104
|
24 |
|
} |
|
105
|
|
|
|
|
106
|
24 |
|
return $items; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
110
|
|
|
| Check Functions |
|
111
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
112
|
|
|
*/ |
|
113
|
|
|
/** |
|
114
|
|
|
* Check if the icons are enabled. |
|
115
|
|
|
* |
|
116
|
|
|
* @return bool |
|
117
|
|
|
*/ |
|
118
|
24 |
|
private function isIconsEnabled() |
|
119
|
|
|
{ |
|
120
|
24 |
|
return (bool) $this->config('menu.icons-enabled', false); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
124
|
|
|
| Other Functions |
|
125
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
126
|
|
|
*/ |
|
127
|
|
|
/** |
|
128
|
|
|
* Get config. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $key |
|
131
|
|
|
* @param mixed|null $default |
|
132
|
|
|
* |
|
133
|
|
|
* @return mixed |
|
134
|
|
|
*/ |
|
135
|
24 |
|
private function config($key, $default = null) |
|
136
|
|
|
{ |
|
137
|
24 |
|
return $this->config->get('log-viewer.' . $key, $default); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|