1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelTracy; |
4
|
|
|
|
5
|
|
|
use Tracy\Bar; |
6
|
|
|
use Tracy\Debugger; |
7
|
|
|
|
8
|
|
|
class Tracy |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* $bar. |
12
|
|
|
* |
13
|
|
|
* @var \Tracy\Bar |
14
|
|
|
*/ |
15
|
|
|
protected $bar; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* __construct. |
19
|
|
|
* |
20
|
|
|
* @param array $config |
21
|
|
|
* @param BarManager $barManager |
22
|
|
|
* @param \Tracy\Bar $bar |
23
|
|
|
*/ |
24
|
1 |
|
public function __construct($config = [], BarManager $barManager = null, Bar $bar = null) |
25
|
|
|
{ |
26
|
1 |
|
$config = array_merge([ |
27
|
1 |
|
'directory' => null, |
28
|
|
|
'email' => null, |
29
|
|
|
'emailSnooze' => null, |
30
|
|
|
'enabled' => true, |
31
|
|
|
'showBar' => true, |
32
|
|
|
'editor' => 'subl://open?url=file://%file&line=%line', |
33
|
|
|
'maxDepth' => 4, |
34
|
|
|
'maxLength' => 1000, |
35
|
|
|
'scream' => true, |
36
|
|
|
'showLocation' => true, |
37
|
|
|
'strictMode' => true, |
38
|
|
|
'panels' => [ |
39
|
|
|
'routing' => false, |
40
|
|
|
'database' => true, |
41
|
|
|
'model' => false, |
42
|
|
|
'view' => false, |
43
|
|
|
'event' => false, |
44
|
|
|
'session' => true, |
45
|
|
|
'request' => true, |
46
|
|
|
'auth' => true, |
47
|
|
|
'terminal' => false, |
48
|
|
|
], |
49
|
|
|
], $config); |
50
|
1 |
|
|
51
|
1 |
|
$mode = $config['enabled'] === true ? Debugger::DEVELOPMENT : Debugger::PRODUCTION; |
52
|
1 |
|
$config = DebuggerManager::init($config); |
53
|
1 |
|
Debugger::enable($mode, $config['directory'], $config['email']); |
54
|
1 |
|
if (is_null($config['emailSnooze']) === false) { |
55
|
|
|
Debugger::getLogger()->emailSnooze = $config['emailSnooze']; |
56
|
|
|
} |
57
|
1 |
|
|
58
|
1 |
|
$bar = $bar ?: Debugger::getBar(); |
59
|
|
|
$barManager = $barManager ?: new BarManager($bar); |
60
|
1 |
|
|
61
|
1 |
|
$this->bar = $barManager->loadPanels($config['panels'])->getBar(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* __call. |
66
|
|
|
* |
67
|
|
|
* @param string $method |
68
|
|
|
* @param array $parameters |
69
|
|
|
* @return mix |
70
|
1 |
|
*/ |
71
|
|
|
public function __call($method, $parameters) |
72
|
1 |
|
{ |
73
|
1 |
|
if (method_exists($this->bar, $method) === true) { |
74
|
|
|
return call_user_func_array([$this->bar, $method], $parameters); |
75
|
|
|
} |
76
|
1 |
|
|
77
|
|
|
return call_user_func_array(['\Tracy\Debugger', $method], $parameters); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* instance. |
82
|
|
|
* |
83
|
|
|
* @param array$config |
84
|
|
|
* @return static |
85
|
1 |
|
*/ |
86
|
|
|
public static function instance($config = [], BarManager $barManager = null, Bar $bar = null) |
87
|
1 |
|
{ |
88
|
|
|
static $instance; |
89
|
1 |
|
|
90
|
1 |
|
if (is_null($instance) === false) { |
91
|
|
|
return $instance; |
92
|
|
|
} |
93
|
1 |
|
|
94
|
|
|
return $instance = new static($config, $barManager, $bar); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|