ConfigPanel.php 1.98 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\debug\panels;

use Yii;
use yii\debug\Panel;

/**
14 15
 * Debugger panel that collects and displays application configuration and environment.
 *
16 17
 * @property array $extensions This property is read-only.
 *
Qiang Xue committed
18 19 20 21 22
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class ConfigPanel extends Panel
{
23 24 25
	/**
	 * @inheritdoc
	 */
Qiang Xue committed
26 27
	public function getName()
	{
Qiang Xue committed
28
		return 'Configuration';
Qiang Xue committed
29 30
	}

31 32 33
	/**
	 * @inheritdoc
	 */
Qiang Xue committed
34 35
	public function getSummary()
	{
Qiang Xue committed
36
		return Yii::$app->view->render('panels/config/summary', ['panel' => $this]);
Qiang Xue committed
37 38
	}

39 40 41
	/**
	 * @inheritdoc
	 */
Qiang Xue committed
42 43
	public function getDetail()
	{
Qiang Xue committed
44
		return Yii::$app->view->render('panels/config/detail', ['panel' => $this]);
Qiang Xue committed
45 46
	}

47 48 49 50 51
	/**
	 * Returns data about extensions
	 *
	 * @return array
	 */
52
	public function getExtensions()
53 54 55
	{
		$data = [];
		foreach ($this->data['extensions'] as $extension) {
Qiang Xue committed
56
			$data[$extension['name']] = $extension['version'];
57
		}
58
		return $data;
59 60
	}

Tobias Munk committed
61 62 63 64 65 66 67 68 69 70 71 72
	/**
	 * Returns the BODY contents of the phpinfo() output
	 *
	 * @return array
	 */
	public function getPhpInfo ()
	{
		ob_start();
		phpinfo();
		$pinfo = ob_get_contents();
		ob_end_clean();
		$phpinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $pinfo);
73
		$phpinfo = str_replace('<table ', '<table class="table table-condensed table-bordered table-striped table-hover config-php-info-table"', $phpinfo);
74

Tobias Munk committed
75 76
		return $phpinfo;
	}
77

78 79 80
	/**
	 * @inheritdoc
	 */
Qiang Xue committed
81 82
	public function save()
	{
Alexander Makarov committed
83
		return [
Qiang Xue committed
84 85
			'phpVersion' => PHP_VERSION,
			'yiiVersion' => Yii::getVersion(),
Alexander Makarov committed
86
			'application' => [
Qiang Xue committed
87 88 89 90
				'yii' => Yii::getVersion(),
				'name' => Yii::$app->name,
				'env' => YII_ENV,
				'debug' => YII_DEBUG,
Alexander Makarov committed
91 92
			],
			'php' => [
Qiang Xue committed
93 94 95 96
				'version' => PHP_VERSION,
				'xdebug' => extension_loaded('xdebug'),
				'apc' => extension_loaded('apc'),
				'memcache' => extension_loaded('memcache'),
Alexander Makarov committed
97
			],
98
			'extensions' => Yii::$app->extensions,
Alexander Makarov committed
99
		];
Qiang Xue committed
100 101
	}
}