|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the fangface/yii2-concord package |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view |
|
6
|
|
|
* the file LICENSE.md that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @package fangface/yii2-concord |
|
9
|
|
|
* @author Fangface <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2014 Fangface <[email protected]> |
|
11
|
|
|
* @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace fangface\debug; |
|
16
|
|
|
|
|
17
|
|
|
use fangface\web\View; |
|
18
|
|
|
use Yii; |
|
19
|
|
|
use yii\base\Application; |
|
20
|
|
|
use yii\base\BootstrapInterface; |
|
21
|
|
|
use yii\base\ViewContextInterface; |
|
22
|
|
|
use yii\debug\LogTarget; |
|
23
|
|
|
use yii\helpers\Html; |
|
24
|
|
|
use yii\helpers\Url; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Extends Yii Debug Module to suppoer ajax debug requests updating the debug toolbar |
|
28
|
|
|
*/ |
|
29
|
|
|
class Module extends \yii\debug\Module implements BootstrapInterface, ViewContextInterface |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Override view path to point back to yii2-debug |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
* @see \yii\base\Module::getViewPath() |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getViewPath() |
|
37
|
|
|
{ |
|
38
|
|
|
return Yii::getAlias(Yii::getAlias('@base') . '/vendor/yiisoft/yii2-debug/views'); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritdoc |
|
43
|
|
|
*/ |
|
44
|
|
|
public function bootstrap($app) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->logTarget = Yii::$app->getLog()->targets['debug'] = new LogTarget($this); |
|
47
|
|
|
|
|
48
|
|
|
if (Yii::$app->getRequest()->getIsAjax()) { |
|
49
|
|
|
if (YII_DEBUG_AJAX) { |
|
50
|
|
|
// delay attaching event handler to the view component after it is fully configured |
|
51
|
|
|
$app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { |
|
52
|
|
|
$app->getView()->on(View::EVENT_END_AJAX_DEBUG, [$this, 'renderToolbar']); |
|
53
|
|
|
}); |
|
54
|
|
|
} |
|
55
|
|
|
} else { |
|
56
|
|
|
// delay attaching event handler to the view component after it is fully configured |
|
57
|
|
|
$app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { |
|
58
|
|
|
$app->getView()->on(View::EVENT_END_BODY, [$this, 'renderToolbar']); |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$app->getUrlManager()->addRules([ |
|
63
|
|
|
[ |
|
64
|
|
|
'class' => 'yii\web\UrlRule', |
|
65
|
|
|
'route' => $this->id, |
|
66
|
|
|
'pattern' => $this->id, |
|
67
|
|
|
], |
|
68
|
|
|
[ |
|
69
|
|
|
'class' => 'yii\web\UrlRule', |
|
70
|
|
|
'route' => $this->id . '/<controller>/<action>', |
|
71
|
|
|
'pattern' => $this->id . '/<controller:[\w\-]+>/<action:[\w\-]+>', |
|
72
|
|
|
] |
|
73
|
|
|
], false); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Renders mini-toolbar at the end of page body. |
|
78
|
|
|
* |
|
79
|
|
|
* @param \yii\base\Event $event |
|
80
|
|
|
*/ |
|
81
|
|
|
public function renderToolbar($event) |
|
82
|
|
|
{ |
|
83
|
|
|
if (!$this->checkAccess()) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$url = Url::toRoute(['/' . $this->id . '/default/toolbar', |
|
88
|
|
|
'tag' => $this->logTarget->tag, |
|
89
|
|
|
]); |
|
90
|
|
|
|
|
91
|
|
|
if (!Yii::$app->getRequest()->getIsAjax()) { |
|
92
|
|
|
echo '<div id="yii-debug-toolbar-wrapper">'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
echo '<div id="yii-debug-toolbar" data-url="' . Html::encode($url) . '" style="display:none" class="yii-debug-toolbar-bottom"></div>'; |
|
96
|
|
|
|
|
97
|
|
|
/* @var $view View */ |
|
98
|
|
|
$view = $event->sender; |
|
99
|
|
|
|
|
100
|
|
|
// echo is used in order to support cases where asset manager is not available |
|
101
|
|
|
echo '<style>' . $view->renderPhpFile(Yii::getAlias('@base/vendor/yiisoft/yii2-debug/assets/toolbar.css')) . '</style>'; |
|
|
|
|
|
|
102
|
|
|
echo '<script>' . $view->renderPhpFile(Yii::getAlias('@base/vendor/yiisoft/yii2-debug/assets/toolbar.js')) . '</script>'; |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
if (!Yii::$app->getRequest()->getIsAjax()) { |
|
105
|
|
|
echo '</div>'; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|