【opencart3源码分析】配置类config.php

<?php
/**
 * @package		OpenCart
 * @author		Daniel Kerr
 * @copyright	Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
 * @license		https://opensource.org/licenses/GPL-3.0
 * @link		https://www.opencart.com
*/

/**
* 配置类
*/
class Config {
    // 配置数组
	private $data = array();
    
	/**
     * 
     *  获取配置
     * @param	string	$key
	 * 
	 * @return	mixed
     */
	public function get($key) {
		return (isset($this->data[$key]) ? $this->data[$key] : null);
	}
	
    /**
     * 
     * 设置配置
     * @param	string	$key
	 * @param	string	$value
     */
	public function set($key, $value) {
		$this->data[$key] = $value;
	}

    /**
     * 
     * 判断是否存在
     * @param	string	$key
	 *
	 * @return	mixed
     */
	public function has($key) {
		return isset($this->data[$key]);
	}
	
    /**
     * 
     * 加载配置文件
     * @param	string	$filename
     */
	public function load($filename) {
		$file = DIR_CONFIG . $filename . '.php';

		if (file_exists($file)) {
			$_ = array();

			require($file);

			$this->data = array_merge($this->data, $_);
		} else {
		    // 创建用户级别的错误消息
			trigger_error('Error: Could not load config ' . $filename . '!');
			exit();
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/81413549
今日推荐