Yii2 framework backup
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.

133 lines
3.1 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;
use yii\web\NotFoundHttpException;
use yii\debug\models\search\Debug;
/**
* @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
11 years ago
*/
public $module;
/**
* @var array the summary data (e.g. URL, time)
*/
public $summary;
11 years ago
public function actions()
{
$actions = [];
foreach($this->module->panels as $panel) {
$actions = array_merge($actions, $panel->actions);
}
return $actions;
}
public function actionIndex()
{
$searchModel = new Debug();
$dataProvider = $searchModel->search($_GET, $this->getManifest());
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}
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', [
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)
{
$this->loadData($tag, 5);
return $this->renderPartial('toolbar', [
'tag' => $tag,
11 years ago
'panels' => $this->module->panels,
'position' => 'bottom',
]);
11 years ago
}
11 years ago
public function actionPhpinfo()
{
phpinfo();
}
11 years ago
private $_manifest;
protected function getManifest($forceReload = false)
11 years ago
{
if ($this->_manifest === null || $forceReload) {
if ($forceReload) {
clearstatcache();
}
11 years ago
$indexFile = $this->module->dataPath . '/index.data';
11 years ago
if (is_file($indexFile)) {
$this->_manifest = array_reverse(unserialize(file_get_contents($indexFile)), true);
11 years ago
} else {
$this->_manifest = [];
11 years ago
}
}
return $this->_manifest;
}
public function loadData($tag, $maxRetry = 0)
11 years ago
{
// retry loading debug data because the debug data is logged in shutdown function
// which may be delayed in some environment if xdebug is enabled.
// See: https://github.com/yiisoft/yii2/issues/1504
for ($retry = 0; $retry <= $maxRetry; ++$retry) {
$manifest = $this->getManifest($retry > 0);
if (isset($manifest[$tag])) {
$dataFile = $this->module->dataPath . "/$tag.data";
$data = unserialize(file_get_contents($dataFile));
foreach ($this->module->panels as $id => $panel) {
if (isset($data[$id])) {
$panel->tag = $tag;
$panel->load($data[$id]);
} else {
// remove the panel since it has not received any data
unset($this->module->panels[$id]);
}
11 years ago
}
$this->summary = $data['summary'];
return;
11 years ago
}
sleep(1);
}
throw new NotFoundHttpException("Unable to find debug data tagged with '$tag'.");
}
11 years ago
}