This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
YiiDebugToolbar.php
215 lines (193 loc) · 4.91 KB
/
YiiDebugToolbar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
* YiiDebugToolbar class file.
*
* @author Sergey Malyshev <[email protected]>
*/
Yii::import('yii-debug-toolbar.panels.*');
Yii::import('yii-debug-toolbar.widgets.*');
/**
* YiiDebugToolbar represents an ...
*
* Description of YiiDebugToolbar
*
* @author Sergey Malyshev <[email protected]>
* @author Igor Golovanov <[email protected]>
* @version $Id$
* @package YiiDebugToolbar
* @since 1.1.7
*/
class YiiDebugToolbar extends CWidget
{
/**
* The URL of assets.
*
* @var string
*/
private $_assetsUrl;
/**
* Panels.
*
* @var array
*/
private $_panels;
/**
* Setup toolbar panels.
*
* @param array $panels Panels.
* @return YiiDebugToolbar
*/
public function setPanels(array $panels = array())
{
$this->_panels = $panels;
return $this;
}
/**
* Get toolbar panels.
*
* @return array
*/
public function getPanels()
{
if(null === $this->_panels)
{
$this->_panels = array();
}
return $this->_panels;
}
/**
* Get the URL of assets.
* The base URL that contains all published asset files of yii-debug-toolbar.
* @return string
*/
public function getAssetsUrl()
{
if (null === $this->_assetsUrl && 'cli' !== php_sapi_name()) {
$linkAssets = Yii::app()->getAssetManager()->linkAssets;
$this->_assetsUrl = Yii::app()
->getAssetManager()
->publish(dirname(__FILE__) . '/assets', false, -1, YII_DEBUG and !$linkAssets);
}
return $this->_assetsUrl;
}
public function getLogs()
{
return $this->owner->logs;
}
/**
* Set the URL of assets.
* The base URL that contains all published asset files of yii-debug-toolbar.
*
* @param string $value
*/
public function setAssetsUrl($value)
{
$this->_assetsUrl = $value;
}
/**
* Initialization.
*/
public function init()
{
if (false === ($this->owner instanceof CLogRoute)) {
throw new CException(YiiDebug::t('YiiDebugToolbar owner must be instance of CLogRoute'));
}
$this->createPanels()
->registerClientScripts();
}
/**
* Run.
*/
public function run()
{
$this->render('main', array(
'panels' => $this->getPanels()
));
}
/**
* Register client scripts.
*
* @return YiiDebugToolbar
*/
private function registerClientScripts()
{
$cs = Yii::app()->getClientScript()
->registerCoreScript('jquery');
$cs->registerCssFile($this->assetsUrl . '/main.css');
$cs->registerScriptFile($this->assetsUrl . '/main.js',
CClientScript::POS_END);
return $this;
}
/**
* Create panels.
*
* @return YiiDebugToolbar
*/
private function createPanels()
{
foreach ($this->getPanels() as $id => $config) {
if (!is_object($config)) {
if (is_string($config)) {
$config = array('class' => $config);
}
if(is_array($config)) {
if (is_array($config) && !isset($config['class'])) {
$config['class'] = $id;
}
if (isset($config['enabled']) && false === $config['enabled']) {
unset($this->_panels[$id]);
continue;
} else if (isset($config['enabled']) && true === $config['enabled']) {
unset($config['enabled']);
}
}
$panel = Yii::createComponent($config, $this);
if (false === ($panel instanceof YiiDebugToolbarPanelInterface)) {
throw new CException(Yii::t('yii-debug-toolbar',
'The %class% class must be compatible with YiiDebugToolbarPanelInterface', array(
'%class%' => get_class($panel)
)));
}
$panel->init();
$this->_panels[$id] = $panel;
}
}
return $this;
}
}
/**
* YiiDebugToolbarPanelInterface
*
* @author Sergey Malyshev <[email protected]>
* @author Igor Golovanov <[email protected]>
* @version $Id$
* @package YiiDebugToolbar
* @since 1.1.7
*/
interface YiiDebugToolbarPanelInterface
{
/**
* Get the title of menu.
*
* @return string
*/
function getMenuTitle();
/**
* Get the subtitle of menu.
*
* @return string
*/
function getMenuSubTitle();
/**
* Get the title.
*
* @return string
*/
function getTitle();
/**
* Get the subtitle.
*
* @return string
*/
function getSubTitle();
}