
---
layout:     readme
title:      "配置加载类"
subtitle:   "Configuration load class"
date:       2019-01-11 20:00:00
author:     "吴庆宝"
tags:
    - phpms框架
---

include CORE.'/lib/conf.php';

```
<?php

namespace core\lib;

class conf
{
	static public $conf = [];

	static public function get($name,$file){		
		/**
		 * 1.判断配置文件是否存在	
		 * 2.判断配置是否存在
		 * 3.缓存配置
		 */
		$file = PHPMSFRAME.'\core\config\\'.$file.'.php';		
		if(isset(self::$conf[$file])){
			return self::$conf[$file][$name];
		}else{			
			if(is_file($file)){
				$conf = include $file;
				if(isset($conf[$name])){
					self::$conf[$file] = $conf;
					return $conf[$name];
				}else{
					throw new Exception("没有这个配置项目", $name);
				}
			}else{
				throw new Exception("没有这个配置文件", $file);
			}				
		}

	}

	static public function all($file){
		$file = PHPMSFRAME.'\core\config\\'.$file.'.php';		
		if(isset(self::$conf[$file])){
			return self::$conf[$file];
		}else{			
			if(is_file($file)){
				$conf = include $file;
				self::$conf[$file] = $conf;
				return $conf;
			}else{
				throw new Exception("没有这个配置文件", $file);
			}				
		}
	}
}
```
