<?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;

/**
 * Debugger panel that collects and displays application configuration and environment.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class ConfigPanel extends Panel
{
	/**
	 * @inheritdoc
	 */
	public function getName()
	{
		return 'Configuration';
	}

	/**
	 * Returns Yii logo ready to use in `<img src="`
	 *
	 * @return string base64 representation of the image
	 */
	public static function getYiiLogo()
	{
		return 'data:image/png;base64,[encoded data, 8400 characters]';
	}

	/**
	 * @inheritdoc
	 */
	public function getSummary()
	{
		return Yii::$app->view->render('panels/config/summary', ['panel' => $this]);
	}

	/**
	 * @inheritdoc
	 */
	public function getDetail()
	{
		return Yii::$app->view->render('panels/config/detail', ['panel' => $this]);
	}

	/**
	 * Returns data about extensions
	 *
	 * @return array
	 */
	public function getExtensions()
	{
		$data = [];
		foreach ($this->data['extensions'] as $extension) {
			$data[$extension['name']] = $extension['version'];
		}
		return $data;
	}

	/**
	 * @inheritdoc
	 */
	public function save()
	{
		return [
			'phpVersion' => PHP_VERSION,
			'yiiVersion' => Yii::getVersion(),
			'application' => [
				'yii' => Yii::getVersion(),
				'name' => Yii::$app->name,
				'env' => YII_ENV,
				'debug' => YII_DEBUG,
			],
			'php' => [
				'version' => PHP_VERSION,
				'xdebug' => extension_loaded('xdebug'),
				'apc' => extension_loaded('apc'),
				'memcache' => extension_loaded('memcache'),
			],
			'extensions' => Yii::$app->extensions,
		];
	}
}
