67 'components/db/username',
68 'components/db/password',
80 if (!$this->enabled)
return;
82 Yii::setPathOfAlias(
'yii2-debug', dirname(__FILE__));
83 Yii::app()->setImport(array(
85 'yii2-debug.panels.*',
88 if ($this->logPath === null) {
89 $this->logPath = Yii::app()->getRuntimePath() .
'/debug';
93 foreach (CMap::mergeArray($this->
corePanels(), $this->panels) as $id =>
$config) {
99 Yii::app()->setModules(array(
100 $this->moduleId => array(
101 'class' =>
'Yii2DebugModule',
106 if ($this->internalUrls && (Yii::app()->getUrlManager()->urlFormat ==
'path')) {
109 $rules[$this->moduleId .
'/' . $key] = $this->moduleId .
'/' . $value;
111 Yii::app()->getUrlManager()->addRules($rules,
false);
114 Yii::app()->attachEventHandler(
'onEndRequest', array($this,
'onEndRequest'));
123 if ($this->_tag === null) $this->_tag = uniqid();
134 'class' =>
'Yii2ConfigPanel',
137 'class' =>
'Yii2RequestPanel',
140 'class' =>
'Yii2LogPanel',
142 'profiling' => array(
143 'class' =>
'Yii2ProfilingPanel',
146 'class' =>
'Yii2DbPanel',
154 '' =>
'default/index',
155 '<tag:[0-9a-f]+>/<action:toolbar|explain>' =>
'default/<action>',
156 '<tag:[0-9a-f]+>/<panel:\w+>' =>
'default/view',
157 'latest/<panel:\w+>' =>
'default/view',
158 '<action:\w+>' =>
'default/<action>',
168 $assetsUrl = CHtml::asset(dirname(__FILE__) .
'/assets');
170 $cs = Yii::app()->getClientScript();
171 $cs->registerCoreScript(
'jquery');
172 $url = Yii::app()->createUrl($this->moduleId .
'/default/toolbar', array(
'tag' => $this->
getTag()));
173 $cs->registerScript(__CLASS__ .
'#toolbar', <<<JS
175 $(
'<div>').appendTo(
'body').load(
'$url',
function(){
176 if (window.localStorage && localStorage.getItem(
'yii2-debug-toolbar') ==
'minimized') {
177 $(
'#yii2-debug-toolbar').hide();
178 $(
'#yii2-debug-toolbar-min').show();
180 $(
'#yii2-debug-toolbar-min').hide();
181 $(
'#yii2-debug-toolbar').show();
183 $(
'#yii2-debug-toolbar .yii2-debug-toolbar-toggler').click(
function(){
184 $(
'#yii2-debug-toolbar').hide();
185 $(
'#yii2-debug-toolbar-min').show();
186 if (window.localStorage) {
187 localStorage.setItem(
'yii2-debug-toolbar',
'minimized');
190 $(
'#yii2-debug-toolbar-min .yii2-debug-toolbar-toggler').click(
function(){
191 $(
'#yii2-debug-toolbar-min').hide();
192 $(
'#yii2-debug-toolbar').show();
193 if (window.localStorage) {
194 localStorage.setItem(
'yii2-debug-toolbar',
'maximized');
217 if (!is_dir($path)) mkdir($path);
219 $indexFile =
"$path/index.data";
221 if (is_file($indexFile)) {
222 $manifest = unserialize(file_get_contents($indexFile));
226 foreach ($this->panels as $panel) {
227 $data[$panel->getId()] = $panel->save();
228 if (isset($panel->filterData)) {
229 $data[$panel->getId()] = $panel->evaluateExpression(
231 array(
'data' =>
$data[$panel->getId()])
234 $panel->load(
$data[$panel->getId()]);
238 if (isset($this->panels[
'request']) && isset($this->panels[
'request']->data[
'statusCode'])) {
239 $statusCode = $this->panels[
'request']->data[
'statusCode'];
242 $request = Yii::app()->getRequest();
243 $manifest[$this->
getTag()] =
$data[
'summary'] = array(
245 'url' => $request->getHostInfo() . $request->getUrl(),
246 'ajax' => $request->getIsAjaxRequest(),
247 'method' => $request->getRequestType(),
248 'code' => $statusCode,
249 'ip' => $request->getUserHostAddress(),
254 file_put_contents(
"$path/{$this->getTag()}.data", serialize(
$data));
255 file_put_contents($indexFile, serialize($manifest));
264 $tags = array_keys($manifest);
266 foreach ($tags as $tag) {
269 if (
$count > $this->historySize + 10) {
272 foreach ($tags as $tag) {
274 @unlink(
"$path/$tag.data");
275 unset($manifest[$tag]);
276 if (--$n <= 0)
break;
289 $this->accessExpression !== null &&
290 !$this->evaluateExpression($this->accessExpression)
294 $ip = Yii::app()->getRequest()->getUserHostAddress();
295 foreach ($this->allowedIPs as $filter) {
297 $filter ===
'*' || $filter === $ip || (
298 ($pos = strpos($filter,
'*')) !==
false &&
299 !strncmp($ip, $filter, $pos)
328 if ($this->_locks === null) {
329 $locksFile = $this->logPath .
'/locks.data';
330 if (is_file($locksFile)) {
331 $this->_locks = array_flip(unserialize(file_get_contents($locksFile)));
333 $this->_locks = array();
336 return isset($this->_locks[$tag]);
346 if ($this->
getLock($tag) !== $value) {
348 $this->_locks[$tag] =
true;
350 unset($this->_locks[$tag]);
352 $locksFile = $this->logPath .
'/locks.data';
353 file_put_contents($locksFile, serialize(array_keys($this->_locks)));
364 static $parents = array();
367 if (is_array(
$data) ||
$data instanceof CMap) {
368 foreach (
$data as $key => $value) {
371 } elseif (is_object(
$data)) {
372 if (!in_array(
$data, $parents,
true)) {
373 array_push($parents,
$data);
374 $result[
'class'] = get_class(
$data);
375 if (
$data instanceof CActiveRecord) {
376 foreach (
$data->attributes as $field => $value) {
377 $result[$field] = $value;
380 foreach (get_object_vars(
$data) as $key => $value) {
385 $result = get_class(
$data) .
'()';