ConfigPanel.php 1.95 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.
 *
Qiang Xue committed
16 17 18 19 20
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class ConfigPanel extends Panel
{
21 22 23
	/**
	 * @inheritdoc
	 */
Qiang Xue committed
24 25
	public function getName()
	{
Qiang Xue committed
26
		return 'Configuration';
Qiang Xue committed
27 28
	}

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

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

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

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    /**
     * 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);
        $phpinfo = str_replace('<table ','<table class="table table-condensed table-bordered table-striped table-hover"',$phpinfo);

        return $phpinfo;
    }

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