You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.3 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\controllers;
use Yii;
use yii\web\Controller;
11 years ago
use yii\web\HttpException;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class DefaultController extends Controller
{
11 years ago
public $layout = 'main';
11 years ago
/**
* @var \yii\debug\Module
*/
public $module;
/**
* @var array the summary data (e.g. URL, time)
*/
public $summary;
11 years ago
public function actionIndex()
{
return $this->render('index', array(
'manifest' => $this->getManifest(),
));
}
public function actionView($tag = null, $panel = null)
{
11 years ago
if ($tag === null) {
$tags = array_keys($this->getManifest());
$tag = reset($tags);
11 years ago
}
11 years ago
$this->loadData($tag);
11 years ago
if (isset($this->module->panels[$panel])) {
$activePanel = $this->module->panels[$panel];
} else {
11 years ago
$activePanel = $this->module->panels['request'];
11 years ago
}
return $this->render('view', array(
11 years ago
'tag' => $tag,
11 years ago
'summary' => $this->summary,
11 years ago
'manifest' => $this->getManifest(),
11 years ago
'panels' => $this->module->panels,
'activePanel' => $activePanel,
));
}
public function actionToolbar($tag)
{
11 years ago
$this->loadData($tag);
return $this->renderPartial('toolbar', array(
'tag' => $tag,
11 years ago
'panels' => $this->module->panels,
));
}
11 years ago
public function actionPhpinfo()
{
phpinfo();
}
11 years ago
private $_manifest;
protected function getManifest()
{
if ($this->_manifest === null) {
$indexFile = $this->module->dataPath . '/index.json';
if (is_file($indexFile)) {
$this->_manifest = array_reverse(json_decode(file_get_contents($indexFile), true), true);
11 years ago
} else {
$this->_manifest = array();
}
}
return $this->_manifest;
}
11 years ago
protected function loadData($tag)
{
11 years ago
$manifest = $this->getManifest();
if (isset($manifest[$tag])) {
$dataFile = $this->module->dataPath . "/$tag.json";
$data = json_decode(file_get_contents($dataFile), true);
11 years ago
foreach ($this->module->panels as $id => $panel) {
11 years ago
if (isset($data[$id])) {
$panel->tag = $tag;
11 years ago
$panel->load($data[$id]);
11 years ago
} else {
// remove the panel since it has not received any data
unset($this->module->panels[$id]);
}
}
11 years ago
$this->summary = $data['summary'];
} else {
11 years ago
throw new HttpException(404, "Unable to find debug data tagged with '$tag'.");
}
}
11 years ago
}