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