init
This commit is contained in:
181
vendor/yiisoft/yii2-debug/controllers/DefaultController.php
vendored
Normal file
181
vendor/yiisoft/yii2-debug/controllers/DefaultController.php
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
<?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;
|
||||
use yii\web\Response;
|
||||
|
||||
/**
|
||||
* Debugger controller
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $layout = 'main';
|
||||
/**
|
||||
* @var \yii\debug\Module
|
||||
*/
|
||||
public $module;
|
||||
/**
|
||||
* @var array the summary data (e.g. URL, time)
|
||||
*/
|
||||
public $summary;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
$actions = [];
|
||||
foreach ($this->module->panels as $panel) {
|
||||
$actions = array_merge($actions, $panel->actions);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public function beforeAction($action)
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_HTML;
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new Debug();
|
||||
$dataProvider = $searchModel->search($_GET, $this->getManifest());
|
||||
|
||||
// load latest request
|
||||
$tags = array_keys($this->getManifest());
|
||||
$tag = reset($tags);
|
||||
$this->loadData($tag);
|
||||
|
||||
return $this->render('index', [
|
||||
'panels' => $this->module->panels,
|
||||
'dataProvider' => $dataProvider,
|
||||
'searchModel' => $searchModel,
|
||||
'manifest' => $this->getManifest(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionView($tag = null, $panel = null)
|
||||
{
|
||||
if ($tag === null) {
|
||||
$tags = array_keys($this->getManifest());
|
||||
$tag = reset($tags);
|
||||
}
|
||||
$this->loadData($tag);
|
||||
if (isset($this->module->panels[$panel])) {
|
||||
$activePanel = $this->module->panels[$panel];
|
||||
} else {
|
||||
$activePanel = $this->module->panels[$this->module->defaultPanel];
|
||||
}
|
||||
|
||||
if ($activePanel->hasError()) {
|
||||
\Yii::$app->errorHandler->handleException($activePanel->getError());
|
||||
}
|
||||
|
||||
return $this->render('view', [
|
||||
'tag' => $tag,
|
||||
'summary' => $this->summary,
|
||||
'manifest' => $this->getManifest(),
|
||||
'panels' => $this->module->panels,
|
||||
'activePanel' => $activePanel,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionToolbar($tag)
|
||||
{
|
||||
$this->loadData($tag, 5);
|
||||
|
||||
return $this->renderPartial('toolbar', [
|
||||
'tag' => $tag,
|
||||
'panels' => $this->module->panels,
|
||||
'position' => 'bottom',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionDownloadMail($file)
|
||||
{
|
||||
$filePath = Yii::getAlias($this->module->panels['mail']->mailPath) . '/' . basename($file);
|
||||
|
||||
if ((mb_strpos($file, '\\') !== false || mb_strpos($file, '/') !== false) || !is_file($filePath)) {
|
||||
throw new NotFoundHttpException('Mail file not found');
|
||||
}
|
||||
|
||||
return Yii::$app->response->sendFile($filePath);
|
||||
}
|
||||
|
||||
private $_manifest;
|
||||
|
||||
protected function getManifest($forceReload = false)
|
||||
{
|
||||
if ($this->_manifest === null || $forceReload) {
|
||||
if ($forceReload) {
|
||||
clearstatcache();
|
||||
}
|
||||
$indexFile = $this->module->dataPath . '/index.data';
|
||||
|
||||
$content = '';
|
||||
$fp = @fopen($indexFile, 'r');
|
||||
if ($fp !== false) {
|
||||
@flock($fp, LOCK_SH);
|
||||
$content = fread($fp, filesize($indexFile));
|
||||
@flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
if ($content !== '') {
|
||||
$this->_manifest = array_reverse(unserialize($content), true);
|
||||
} else {
|
||||
$this->_manifest = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_manifest;
|
||||
}
|
||||
|
||||
public function loadData($tag, $maxRetry = 0)
|
||||
{
|
||||
// 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));
|
||||
$exceptions = $data['exceptions'];
|
||||
foreach ($this->module->panels as $id => $panel) {
|
||||
if (isset($data[$id])) {
|
||||
$panel->tag = $tag;
|
||||
$panel->load(unserialize($data[$id]));
|
||||
}
|
||||
if (isset($exceptions[$id])) {
|
||||
$panel->setError($exceptions[$id]);
|
||||
}
|
||||
}
|
||||
$this->summary = $data['summary'];
|
||||
|
||||
return;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException("Unable to find debug data tagged with '$tag'.");
|
||||
}
|
||||
}
|
||||
60
vendor/yiisoft/yii2-debug/controllers/UserController.php
vendored
Normal file
60
vendor/yiisoft/yii2-debug/controllers/UserController.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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\debug\models\UserSwitch;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
|
||||
/**
|
||||
* User controller
|
||||
*
|
||||
* @author Semen Dubina <yii2debug@sam002.net>
|
||||
* @since 2.0.10
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function beforeAction($action)
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
if (!Yii::$app->session->hasSessionId) {
|
||||
throw new BadRequestHttpException('Need an active session');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new identity, switch user
|
||||
* @return \yii\web\User
|
||||
*/
|
||||
public function actionSetIdentity()
|
||||
{
|
||||
$user_id = Yii::$app->request->post('user_id');
|
||||
|
||||
$userSwitch = new UserSwitch();
|
||||
$newIdentity = Yii::$app->user->identity->findIdentity($user_id);
|
||||
$userSwitch->setUserByIdentity($newIdentity);
|
||||
return Yii::$app->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset identity, switch to main user
|
||||
* @return \yii\web\User
|
||||
*/
|
||||
public function actionResetIdentity()
|
||||
{
|
||||
$userSwitch = new UserSwitch();
|
||||
$userSwitch->reset();
|
||||
return Yii::$app->user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user