17 changed files with 596 additions and 110 deletions
			
			
		| @ -0,0 +1,37 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace yii\debug\models\search; | ||||||
|  | 
 | ||||||
|  | use yii\base\Model; | ||||||
|  | use yii\debug\components\search\Filter; | ||||||
|  | use yii\debug\components\search\matches; | ||||||
|  | 
 | ||||||
|  | class Base extends Model | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @param Filter $filter | ||||||
|  | 	 * @param string $attribute | ||||||
|  | 	 * @param boolean $partial | ||||||
|  | 	 */ | ||||||
|  | 	public function addCondition($filter, $attribute, $partial = false) | ||||||
|  | 	{ | ||||||
|  | 		$value = $this->$attribute; | ||||||
|  | 
 | ||||||
|  | 		if (mb_strpos($value, '>') !== false) { | ||||||
|  | 
 | ||||||
|  | 			$value = intval(str_replace('>', '', $value)); | ||||||
|  | 			$filter->addMatch($attribute, new matches\Greater(['value' => $value])); | ||||||
|  | 
 | ||||||
|  | 		} elseif (mb_strpos($value, '<') !== false) { | ||||||
|  | 
 | ||||||
|  | 			$value = intval(str_replace('<', '', $value)); | ||||||
|  | 			$filter->addMatch($attribute, new matches\Lower(['value' => $value])); | ||||||
|  | 
 | ||||||
|  | 		} else { | ||||||
|  | 			$filter->addMatch($attribute, new matches\Exact(['value' => $value, 'partial' => $partial])); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,79 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace yii\debug\models\search; | ||||||
|  | 
 | ||||||
|  | use yii\data\ArrayDataProvider; | ||||||
|  | use yii\debug\components\search\Filter; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Log represents the model behind the search form about current request log. | ||||||
|  |  */ | ||||||
|  | class Log extends Base | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @var string ip attribute input search value | ||||||
|  | 	 */ | ||||||
|  | 	public $level; | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @var string method attribute input search value | ||||||
|  | 	 */ | ||||||
|  | 	public $category; | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @var integer ajax attribute input search value | ||||||
|  | 	 */ | ||||||
|  | 	public $message; | ||||||
|  | 
 | ||||||
|  | 	public function rules() | ||||||
|  | 	{ | ||||||
|  | 		return [ | ||||||
|  | 			[['level', 'message', 'category'], 'safe'], | ||||||
|  | 		]; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @inheritdoc | ||||||
|  | 	 */ | ||||||
|  | 	public function attributeLabels() | ||||||
|  | 	{ | ||||||
|  | 		return [ | ||||||
|  | 			'level' => 'Level', | ||||||
|  | 			'category' => 'Category', | ||||||
|  | 			'message' => 'Message', | ||||||
|  | 		]; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Returns data provider with filled models. Filter applied if needed. | ||||||
|  | 	 * @param array $params | ||||||
|  | 	 * @param array $models | ||||||
|  | 	 * @return \yii\data\ArrayDataProvider | ||||||
|  | 	 */ | ||||||
|  | 	public function search($params, $models) | ||||||
|  | 	{ | ||||||
|  | 		$dataProvider = new ArrayDataProvider([ | ||||||
|  | 			'allModels' => $models, | ||||||
|  | 			'pagination' => [ | ||||||
|  | 				'pageSize' => 10, | ||||||
|  | 			], | ||||||
|  | 			'sort' => [ | ||||||
|  | 				'attributes' => ['time','level','category','message'], | ||||||
|  | 			], | ||||||
|  | 		]); | ||||||
|  | 
 | ||||||
|  | 		if (!($this->load($params) && $this->validate())) { | ||||||
|  | 			return $dataProvider; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		$filter = new Filter(); | ||||||
|  | 		$this->addCondition($filter, 'level'); | ||||||
|  | 		$this->addCondition($filter, 'category', true); | ||||||
|  | 		$this->addCondition($filter, 'message', true); | ||||||
|  | 		$dataProvider->allModels = $filter->filter($models); | ||||||
|  | 
 | ||||||
|  | 		return $dataProvider; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,73 @@ | |||||||
|  | <?php | ||||||
|  | use yii\helpers\Html; | ||||||
|  | use yii\grid\GridView; | ||||||
|  | use yii\data\ArrayDataProvider; | ||||||
|  | use yii\log\Logger; | ||||||
|  | ?> | ||||||
|  | <h1>Log Messages</h1> | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | echo GridView::widget([ | ||||||
|  | 	'dataProvider' => $dataProvider, | ||||||
|  | 	'id' => 'log-panel-detailed-grid', | ||||||
|  | 	'filterModel' => $searchModel, | ||||||
|  | 	'filterUrl' => $panel->getUrl(), | ||||||
|  | 	'rowOptions' => function ($model, $key, $index, $grid){ | ||||||
|  | 		switch($model['level']) { | ||||||
|  | 			case Logger::LEVEL_ERROR : return ['class' => 'danger']; | ||||||
|  | 			case Logger::LEVEL_WARNING : return ['class' => 'warning']; | ||||||
|  | 			case Logger::LEVEL_INFO : return ['class' => 'success']; | ||||||
|  | 			default: return []; | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | 	'columns' => [ | ||||||
|  | 		['class' => 'yii\grid\SerialColumn'], | ||||||
|  | 		[ | ||||||
|  | 			'attribute' => 'time', | ||||||
|  | 			'value' => function ($data) | ||||||
|  | 			{ | ||||||
|  | 				$timeInSeconds = $data['time'] / 1000; | ||||||
|  | 				$millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000); | ||||||
|  | 				return date('H:i:s.',$timeInSeconds) . sprintf('%03d',$millisecondsDiff); | ||||||
|  | 			}, | ||||||
|  | 		], | ||||||
|  | 		[ | ||||||
|  | 			'attribute' => 'level', | ||||||
|  | 			'value' => function ($data) | ||||||
|  | 			{ | ||||||
|  | 				return Logger::getLevelName($data['level']); | ||||||
|  | 			}, | ||||||
|  | 			'filter' => [ | ||||||
|  | 				Logger::LEVEL_TRACE => ' Trace ', | ||||||
|  | 				Logger::LEVEL_PROFILE => ' Profile ', | ||||||
|  | 				Logger::LEVEL_INFO => ' Info ', | ||||||
|  | 				Logger::LEVEL_ERROR => ' Error ', | ||||||
|  | 			], | ||||||
|  | 		], | ||||||
|  | 		'category', | ||||||
|  | 		[ | ||||||
|  | 			'attribute' => 'message', | ||||||
|  | 			'value' => function ($data) | ||||||
|  | 			{ | ||||||
|  | 				$message = nl2br(Html::encode($data['message'])); | ||||||
|  | 
 | ||||||
|  | 				if (!empty($data['trace'])) { | ||||||
|  | 					$message .= Html::ul($data['trace'], [ | ||||||
|  | 						'class' => 'trace', | ||||||
|  | 						'item' => function ($trace) | ||||||
|  | 						{ | ||||||
|  | 							return "<li>{$trace['file']} ({$trace['line']})</li>"; | ||||||
|  | 						} | ||||||
|  | 					]); | ||||||
|  | 				}; | ||||||
|  | 
 | ||||||
|  | 				return $message; | ||||||
|  | 			}, | ||||||
|  | 			'format' => 'html', | ||||||
|  | 			'options' => [ | ||||||
|  | 				'width' => '50%', | ||||||
|  | 			], | ||||||
|  | 		], | ||||||
|  | 	], | ||||||
|  | ]); | ||||||
|  | ?> | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | <?php | ||||||
|  | use yii\log\Target; | ||||||
|  | use yii\log\Logger; | ||||||
|  | ?> | ||||||
|  | 
 | ||||||
|  | <?php | ||||||
|  | $title = 'Logged ' . count($data['messages']) . ' messages'; | ||||||
|  | $errorCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_ERROR)); | ||||||
|  | $warningCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_WARNING)); | ||||||
|  | $output = []; | ||||||
|  | 
 | ||||||
|  | if ($errorCount) { | ||||||
|  | 	$output[] = "<span class=\"label label-important\">$errorCount</span>"; | ||||||
|  | 	$title .= ", $errorCount errors"; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | if ($warningCount) { | ||||||
|  | 	$output[] = "<span class=\"label label-warning\">$warningCount</span>"; | ||||||
|  | 	$title .= ", $warningCount warnings"; | ||||||
|  | } | ||||||
|  | ?> | ||||||
|  | 
 | ||||||
|  | <div class="yii-debug-toolbar-block"> | ||||||
|  | 	<a href="<?php echo $panel->getUrl(); ?>" title="<?php echo $title ?>">Log
 | ||||||
|  | 		<span class="label"><?php echo count($data['messages']); ?></span>
 | ||||||
|  | 		<?php echo implode(' ', $output); ?> | ||||||
|  | 	</a> | ||||||
|  | </div> | ||||||
| @ -0,0 +1,74 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Simple file system wrapper for twig to process twig files | ||||||
|  |  * | ||||||
|  |  * @link http://www.yiiframework.com/ | ||||||
|  |  * @copyright Copyright (c) 2008 Yii Software LLC | ||||||
|  |  * @license http://www.yiiframework.com/license/ | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | namespace yii\twig; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Twig view file loader class. | ||||||
|  |  * | ||||||
|  |  * @author dev-mraj <dev.meghraj@gmail.com> | ||||||
|  |  */ | ||||||
|  | class TwigSimpleFileLoader implements \Twig_LoaderInterface | ||||||
|  | { | ||||||
|  | 	/** | ||||||
|  | 	 * @var string Path to directory | ||||||
|  | 	 */ | ||||||
|  | 	private $_dir; | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @param string $dir path to directory | ||||||
|  | 	 */ | ||||||
|  | 	public function __construct($dir) | ||||||
|  | 	{ | ||||||
|  | 		$this->_dir = $dir; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Compare a file's freshness with previously stored timestamp | ||||||
|  | 	 * | ||||||
|  | 	 * @param $name string file name to check | ||||||
|  | 	 * @param $time int timestamp to compare with | ||||||
|  | 	 * @return boolean true if file is still fresh and not changes, false otherwise | ||||||
|  | 	 */ | ||||||
|  | 	public function isFresh($name, $time) | ||||||
|  | 	{ | ||||||
|  | 		return filemtime($this->getFilePath($name)) <= $time; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Get the source of given file name | ||||||
|  | 	 * | ||||||
|  | 	 * @param string $name file name | ||||||
|  | 	 * @return string contents of given file name | ||||||
|  | 	 */ | ||||||
|  | 	public function getSource($name) | ||||||
|  | 	{ | ||||||
|  | 		return file_get_contents($this->getFilePath($name)); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Get unique key that can represent this file uniquely among other files. | ||||||
|  | 	 * @param string $name | ||||||
|  | 	 * @return string | ||||||
|  | 	 */ | ||||||
|  | 	public function getCacheKey($name) | ||||||
|  | 	{ | ||||||
|  | 		return $this->getFilePath($name); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * internally used to get absolute path of given file name | ||||||
|  | 	 * @param string $name file name | ||||||
|  | 	 * @return string absolute path of file | ||||||
|  | 	 */ | ||||||
|  | 	protected  function getFilePath($name){ | ||||||
|  | 		return $this->_dir . '/' . $name; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -0,0 +1,43 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Twig ViewRendererStaticClassProxy class file. | ||||||
|  |  * | ||||||
|  |  * @link http://www.yiiframework.com/ | ||||||
|  |  * @copyright Copyright © 2008 Yii Software LLC | ||||||
|  |  * @license http://www.yiiframework.com/license/ | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | namespace yii\twig; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Class-proxy for static classes | ||||||
|  |  * Needed because you can't pass static class to Twig other way | ||||||
|  |  * | ||||||
|  |  * @author Leonid Svyatov <leonid@svyatov.ru> | ||||||
|  |  */ | ||||||
|  | class ViewRendererStaticClassProxy | ||||||
|  | { | ||||||
|  | 	private $_staticClassName; | ||||||
|  | 
 | ||||||
|  |     public function __construct($staticClassName) { | ||||||
|  | 		$this->_staticClassName = $staticClassName; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function __get($property) | ||||||
|  | 	{ | ||||||
|  | 		$class = new \ReflectionClass($this->_staticClassName); | ||||||
|  | 		return $class->getStaticPropertyValue($property); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function __set($property, $value) | ||||||
|  | 	{ | ||||||
|  | 		$class = new \ReflectionClass($this->_staticClassName); | ||||||
|  | 		$class->setStaticPropertyValue($property, $value); | ||||||
|  | 		return $value; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function __call($method, $arguments) | ||||||
|  | 	{ | ||||||
|  | 		return call_user_func_array(array($this->_staticClassName, $method), $arguments); | ||||||
|  | 	} | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue