Commit 7fa240be by Qiang Xue

initial implementation of Yii debugger.

parent 30ec0afd
......@@ -3,6 +3,13 @@
return array(
'id' => 'bootstrap',
'basePath' => dirname(__DIR__),
'preload' => array('debug'),
'modules' => array(
'debug' => array(
'class' => 'yii\debug\Module',
'enabled' => YII_DEBUG && YII_ENV === 'dev',
),
),
'components' => array(
'cache' => array(
'class' => 'yii\caching\FileCache',
......
......@@ -18,8 +18,8 @@ $this->registerAssetBundle('app');
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody(); ?>
<div class="container">
<?php $this->beginBody(); ?>
<div class="masthead">
<h3 class="muted">My Company</h3>
......@@ -57,8 +57,8 @@ $this->registerAssetBundle('app');
Template by <a href="http://twitter.github.io/bootstrap/">Twitter Bootstrap</a>
</p>
</div>
<?php $this->endBody(); ?>
</div>
<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
......@@ -2,6 +2,7 @@
// comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../vendor/autoload.php');
......
......@@ -53,9 +53,6 @@ return array(
'css' => array(
'main.css',
),
'js' => array(
'yii.debug.js',
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
......
......@@ -281,8 +281,8 @@ class Command extends \yii\base\Component
return 0;
}
try {
$token = "SQL: $sql";
try {
Yii::beginProfile($token, __METHOD__);
$this->prepare();
......@@ -403,8 +403,8 @@ class Command extends \yii\base\Component
}
}
try {
$token = "SQL: $sql";
try {
Yii::beginProfile($token, __METHOD__);
$this->prepare();
......
......@@ -40,11 +40,14 @@ class Module extends \yii\base\Module
*/
public $dataPath = '@runtime/debug';
public $historySize = 50;
public $enabled = true;
public function init()
{
parent::init();
if (!$this->enabled) {
return;
}
$this->dataPath = Yii::getAlias($this->dataPath);
$this->logTarget = Yii::$app->getLog()->targets['debug'] = new LogTarget($this);
Yii::$app->getView()->on(View::EVENT_END_BODY, array($this, 'renderToolbar'));
......@@ -72,19 +75,17 @@ class Module extends \yii\base\Module
public function renderToolbar($event)
{
/** @var View $view */
$id = 'yii-debug-toolbar';
$tag = $this->logTarget->tag;
$url = Yii::$app->getUrlManager()->createUrl('debug/default/toolbar', array(
'tag' => $tag,
'tag' => $this->logTarget->tag,
));
$view = $event->sender;
$view->registerJs("yii.debug.load('$id', '$url');");
$view->registerAssetBundle('yii/debug');
echo Html::tag('div', '', array(
'id' => $id,
'id' => 'yii-debug-toolbar',
'data-url' => $url,
'style' => 'display: none',
));
/** @var View $view */
$view = $event->sender;
echo '<script>' . $view->renderFile(__DIR__ . '/views/default/toolbar.js') . '</script>';
}
protected function corePanels()
......
......@@ -41,6 +41,17 @@
vertical-align: middle;
}
.yii-debug-toolbar-block.title {
display: block;
float: left;
padding: 4px 8px 4px 20px;
margin-left: -20px;
font-size: 20px;
font-weight: 200;
color: #777777;
text-shadow: 0 1px 0 #ffffff;
}
span.indent {
color: #ccc;
}
/**
* Yii debug module.
*
* This JavaScript module provides the functions needed by the Yii debug toolbar.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
yii.debug = (function ($) {
return {
load: function (id, url) {
$.ajax({
url: url,
//dataType: 'json',
success: function(data) {
var $e = $('#' + id);
$e.html(data).show();
}
});
}
};
})(jQuery);
......@@ -55,7 +55,7 @@ EOD;
return "<h1>Configuration</h1>\n"
. $this->renderData('Application Configuration', $app) . "\n"
. $this->renderData('PHP Configuration', $php) . "\n"
. '<div>' . Html::a('Complete phpinfo()', array('phpinfo'), array('class' => 'btn btn-info')) . "</div>\n";
. '<div>' . Html::a('phpinfo()', array('phpinfo'), array('class' => 'btn btn-info')) . "</div>\n";
}
protected function renderData($caption, $values)
......
......@@ -28,16 +28,12 @@ class LogPanel extends Panel
{
$output = array();
$errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
if ($errorCount === 1) {
$output[] = '1 error';
} elseif ($errorCount > 1) {
$output[] = "$errorCount errors";
if ($errorCount) {
$output[] = '<span class="label label-important">$errorCount</span> ' . ($errorCount > 1 ? 'errors' : 'error');
}
$warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
if ($warningCount === 1) {
$output[] = '1 warning';
} elseif ($warningCount > 1) {
$output[] = "$warningCount warnings";
if ($warningCount) {
$output[] = '<span class="label label-warning">$warningCount</span> ' . ($warningCount > 1 ? 'warnings' : 'warning');
}
if (!empty($output)) {
$log = implode(', ', $output);
......
......@@ -25,8 +25,8 @@ class RequestPanel extends Panel
public function getSummary()
{
$memory = sprintf('%.1f MB', $this->data['memory'] / 1048576);
$time = number_format($this->data['time'] * 1000) . ' ms';
$memory = '<span class="label">' . sprintf('%.1f MB', $this->data['memory'] / 1048576) . '</span>';
$time = '<span class="label">' . number_format($this->data['time'] * 1000) . ' ms</span>';
return <<<EOD
<div class="yii-debug-toolbar-block">
......@@ -36,6 +36,10 @@ Peak memory: $memory
<div class="yii-debug-toolbar-block">
Time spent: $time
</div>
<div class="yii-debug-toolbar-block">
Action: {$this->data['action']}
</div>
EOD;
}
......
......@@ -18,6 +18,9 @@ $this->title = 'Yii Debugger';
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<div class="yii-debug-toolbar-block title">
Yii Debugger
</div>
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
......
#yii-debug-toolbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
z-index: 1000000;
font: 12px Verdana, Arial, sans-serif;
text-align: left;
height: 38px;
border-top: 1px solid #ccc;
background: rgb(237,237,237);
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VkZWRlZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUzJSIgc3RvcC1jb2xvcj0iI2Y2ZjZmNiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(237,237,237,1) 0%, rgba(246,246,246,1) 53%, rgba(255,255,255,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(237,237,237,1)), color-stop(53%,rgba(246,246,246,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: linear-gradient(to bottom, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ededed', endColorstr='#ffffff',GradientType=0 );
}
.yii-debug-toolbar-block {
float: left;
margin: 0;
border-right: 1px solid #e4e4e4;
padding: 4px 8px;
line-height: 32px;
}
.yii-debug-toolbar-block a {
text-decoration: none;
color: black;
}
.yii-debug-toolbar-block span {
}
.yii-debug-toolbar-block img {
vertical-align: middle;
}
#yii-debug-toolbar .label {
display: inline-block;
padding: 2px 4px;
font-size: 11.844px;
font-weight: bold;
line-height: 14px;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
white-space: nowrap;
vertical-align: baseline;
background-color: #999999;
}
#yii-debug-toolbar .label {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
#yii-debug-toolbar .label:empty {
display: none;
}
#yii-debug-toolbar a.label:hover,
#yii-debug-toolbar a.label:focus {
color: #ffffff;
text-decoration: none;
cursor: pointer;
}
#yii-debug-toolbar .label-important {
background-color: #b94a48;
}
#yii-debug-toolbar .label-important[href] {
background-color: #953b39;
}
#yii-debug-toolbar .label-warning,
#yii-debug-toolbar .badge-warning {
background-color: #f89406;
}
#yii-debug-toolbar .label-warning[href] {
background-color: #c67605;
}
#yii-debug-toolbar .label-success {
background-color: #468847;
}
#yii-debug-toolbar .label-success[href] {
background-color: #356635;
}
#yii-debug-toolbar .label-info {
background-color: #3a87ad;
}
#yii-debug-toolbar .label-info[href] {
background-color: #2d6987;
}
#yii-debug-toolbar .label-inverse,
#yii-debug-toolbar .badge-inverse {
background-color: #333333;
}
#yii-debug-toolbar .label-inverse[href],
#yii-debug-toolbar .badge-inverse[href] {
background-color: #1a1a1a;
}
#yii-debug-toolbar .debugger-link a {
padding: 3px 5px;
font-weight: normal;
color: white;
}
(function() {
var ajax = function(url, settings) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
settings = settings || {};
xhr.open(settings.method || 'GET', url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = function(state) {
if (xhr.readyState == 4) {
if (xhr.status == 200 && settings.success) {
settings.success(xhr);
} else if (xhr.status != 200 && settings.error) {
settings.error(xhr);
}
}
};
xhr.send(settings.data || '');
};
var e = document.getElementById('yii-debug-toolbar');
if (e) {
e.style.display = 'block';
var url = e.getAttribute('data-url');
ajax(url, {
success: function(xhr) {
e.innerHTML = xhr.responseText;
},
error: function(xhr) {
e.innerHTML = xhr.responseText;
}
});
}
})();
......@@ -7,51 +7,12 @@
use yii\helpers\Html;
?>
<style>
#yii-debug-toolbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
z-index: 1000000;
font: 11px Verdana, Arial, sans-serif;
text-align: left;
height: 38px;
border-top: 1px solid #ccc;
background: rgb(237,237,237);
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VkZWRlZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUzJSIgc3RvcC1jb2xvcj0iI2Y2ZjZmNiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(237,237,237,1) 0%, rgba(246,246,246,1) 53%, rgba(255,255,255,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(237,237,237,1)), color-stop(53%,rgba(246,246,246,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: linear-gradient(to bottom, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ededed', endColorstr='#ffffff',GradientType=0 );
}
.yii-debug-toolbar-block {
float: left;
margin: 0;
border-right: 1px solid #e4e4e4;
padding: 4px 8px;
line-height: 32px;
}
.yii-debug-toolbar-block a {
text-decoration: none;
color: black !important;
}
.yii-debug-toolbar-block span {
}
.yii-debug-toolbar-block img {
vertical-align: middle;
}
<?php echo $this->renderFile(__DIR__ . '/toolbar.css'); ?>
</style>
<div id="yii-debug-toolbar">
<div class="yii-debug-toolbar-block debugger-link">
<?php echo Html::a('Yii Debugger', array('index', 'tag' => $tag), array('class' => 'label')); ?>
</div>
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment