1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Webino (http://webino.sk/) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/webino/WebinoDraw/ for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2012-2018 Webino, s. r. o. (http://webino.sk/) |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace WebinoDraw\Debugger; |
11
|
|
|
|
12
|
|
|
use Tracy\Dumper; |
13
|
|
|
use WebinoDebug\Debugger\AbstractPanel; |
14
|
|
|
use WebinoDebug\Debugger\PanelInitInterface; |
15
|
|
|
use WebinoDebug\Debugger\PanelInterface; |
16
|
|
|
use WebinoDebug\Exception; |
17
|
|
|
use WebinoDraw\Service\DrawProfiler; |
18
|
|
|
use Zend\ServiceManager\ServiceManager; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class DrawPanel |
22
|
|
|
*/ |
23
|
|
|
class DrawPanel extends AbstractPanel implements |
24
|
|
|
PanelInterface, |
25
|
|
|
PanelInitInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Profiler bar panel id |
29
|
|
|
*/ |
30
|
|
|
const ID = 'WebinoDraw:draw'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected $dir = __DIR__; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var DrawProfiler |
39
|
|
|
*/ |
40
|
|
|
private $profiler; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $title = 'WebinoDraw profiler'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ServiceManager $services |
49
|
|
|
*/ |
50
|
|
|
public function init(ServiceManager $services) |
51
|
|
|
{ |
52
|
|
|
$this->setProfiler($services->get(DrawProfiler::class)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return DrawProfiler |
57
|
|
|
* @throws Exception\LogicException |
58
|
|
|
*/ |
59
|
|
|
protected function getProfiler() |
60
|
|
|
{ |
61
|
|
|
if (null === $this->profiler) { |
62
|
|
|
throw new Exception\LogicException('Expected `profiler`'); |
63
|
|
|
} |
64
|
|
|
return $this->profiler; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param object|DrawProfiler $profiler |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
|
|
public function setProfiler(DrawProfiler $profiler) |
72
|
|
|
{ |
73
|
|
|
$this->profiler = $profiler; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $var mixed |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function dump($var) : string |
82
|
|
|
{ |
83
|
|
|
if (!class_exists(Dumper::class)) { |
84
|
|
|
return 'Required: ' . Dumper::class; |
85
|
|
|
} |
86
|
|
|
return Dumper::toHtml($var, [Dumper::DEPTH => 10, Dumper::COLLAPSE => 1]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function getTab() |
93
|
|
|
{ |
94
|
|
|
$profiler = $this->getProfiler(); |
95
|
|
|
if (!$profiler || empty($profiler->getData())) { |
96
|
|
|
return ''; |
97
|
|
|
} |
98
|
|
|
return $this->createIcon('draw', 'top: -3px;') . parent::getTab(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
|
|
public function getPanel() |
105
|
|
|
{ |
106
|
|
|
return $this->renderTemplate('draw.panel'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|