Browse Source

minor enhancement of debugger.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
1f63bf0040
  1. 27
      framework/yii/debug/Module.php
  2. 8
      framework/yii/debug/assets/main.css
  3. 5
      framework/yii/debug/panels/DbPanel.php
  4. 2
      framework/yii/debug/panels/LogPanel.php
  5. 4
      framework/yii/debug/panels/ProfilingPanel.php
  6. 4
      framework/yii/debug/panels/RequestPanel.php

27
framework/yii/debug/Module.php

@ -9,6 +9,7 @@ namespace yii\debug;
use Yii;
use yii\base\View;
use yii\web\HttpException;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
@ -64,17 +65,20 @@ class Module extends \yii\base\Module
unset(Yii::$app->getLog()->targets['debug']);
$this->logTarget = null;
$ip = Yii::$app->getRequest()->getUserIP();
foreach ($this->allowedIPs as $filter) {
if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) {
return parent::beforeAction($action);
}
if ($this->checkAccess($action)) {
return true;
} elseif ($action->id === 'toolbar') {
return false;
} else {
throw new HttpException(403, 'You are not allowed to access this page.');
}
return false;
}
public function renderToolbar($event)
{
if (!$this->checkAccess()) {
return;
}
$url = Yii::$app->getUrlManager()->createUrl($this->id . '/default/toolbar', array(
'tag' => $this->logTarget->tag,
));
@ -85,6 +89,17 @@ class Module extends \yii\base\Module
echo '<script>' . $view->renderPhpFile(__DIR__ . '/views/default/toolbar.js') . '</script>';
}
protected function checkAccess()
{
$ip = Yii::$app->getRequest()->getUserIP();
foreach ($this->allowedIPs as $filter) {
if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) {
return true;
}
}
return false;
}
protected function corePanels()
{
return array(

8
framework/yii/debug/assets/main.css

@ -1,4 +1,12 @@
body {
padding-top: 60px;
}
#yii-debug-toolbar {
position: fixed;
top: 0;
left: 0;
right: 0;
margin: 0 0 20px 0;
padding: 0;
z-index: 1000000;

5
framework/yii/debug/panels/DbPanel.php

@ -36,9 +36,8 @@ class DbPanel extends Panel
$url = $this->getUrl();
$output = <<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url">
DB queries: <span class="label">$queryCount</span>
time: <span class="label">$queryTime</span>
<a href="$url" title="Executed $queryCount database queries which took $queryTime.">
DB <span class="label">$queryCount</span> <span class="label">$queryTime</span>
</a>
</div>
EOD;

2
framework/yii/debug/panels/LogPanel.php

@ -44,7 +44,7 @@ class LogPanel extends Panel
$url = $this->getUrl();
return <<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="$title">Log: $log</a>
<a href="$url" title="$title">Log $log</a>
</div>
EOD;
}

4
framework/yii/debug/panels/ProfilingPanel.php

@ -33,10 +33,10 @@ class ProfilingPanel extends Panel
return <<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="Total processing time">Time: <span class="label">$time</span></a>
<a href="$url" title="Total request processing time was $time">Time <span class="label">$time</span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="$url" title="Peak memory consumption">Memory: <span class="label">$memory</span></a>
<a href="$url" title="Peak memory consumption">Memory <span class="label">$memory</span></a>
</div>
EOD;
}

4
framework/yii/debug/panels/RequestPanel.php

@ -45,10 +45,10 @@ class RequestPanel extends Panel
return <<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="Status code: $statusCode $statusText">Status: <span class="label $class">$statusCode</span></a>
<a href="$url" title="Status code: $statusCode $statusText">Status <span class="label $class">$statusCode</span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="$url">Action: <span class="label">{$this->data['action']}</span></a>
<a href="$url">Action <span class="label">{$this->data['action']}</span></a>
</div>
EOD;
}

Loading…
Cancel
Save