mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-20 02:16:41 +08:00
debug toolbar WIP
This commit is contained in:
@ -9,6 +9,7 @@ namespace yii\debug\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use yii\web\HttpException;
|
||||
|
||||
/**
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
@ -16,22 +17,48 @@ use yii\web\Controller;
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/** @var \yii\debug\Module */
|
||||
public $module;
|
||||
public $layout = 'main';
|
||||
|
||||
public function actionIndex($tag)
|
||||
public function actionIndex($tag, $panel = null)
|
||||
{
|
||||
return $this->render('index');
|
||||
$this->loadData($tag);
|
||||
if (isset($this->module->panels[$panel])) {
|
||||
$activePanel = $this->module->panels[$panel];
|
||||
} else {
|
||||
$activePanel = reset($this->module->panels);
|
||||
}
|
||||
return $this->render('index', array(
|
||||
'tag' => $tag,
|
||||
'panels' => $this->module->panels,
|
||||
'activePanel' => $activePanel,
|
||||
));
|
||||
}
|
||||
|
||||
public function actionToolbar($tag)
|
||||
{
|
||||
$this->loadData($tag);
|
||||
return $this->renderPartial('toolbar', array(
|
||||
'panels' => $this->module->panels,
|
||||
));
|
||||
}
|
||||
|
||||
protected function loadData($tag)
|
||||
{
|
||||
$file = Yii::$app->getRuntimePath() . "/debug/$tag.log";
|
||||
if (preg_match('/^[\w\-]+$/', $tag) && is_file($file)) {
|
||||
$data = json_decode(file_get_contents($file), true);
|
||||
$data['tag'] = $tag;
|
||||
return $this->renderPartial('toolbar', $data);
|
||||
foreach ($this->module->panels as $id => $panel) {
|
||||
if (isset($data[$panel->id])) {
|
||||
$panel->load($data[$panel->id]);
|
||||
} else {
|
||||
// remove the panel since it has not received any data
|
||||
unset($this->module->panels[$id]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return "Unable to find debug data tagged with '$tag'.";
|
||||
throw new HttpException(404, "Unable to find debug data tagged with '$tag'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user