diff --git a/core/ppphp/conf.php b/core/ppphp/conf.php index ec2723c..f70dfc2 100755 --- a/core/ppphp/conf.php +++ b/core/ppphp/conf.php @@ -14,46 +14,29 @@ class conf static public $conf = array(); /** - * 加载系统配置,如果之前已经加载过,那么就直接返回 - * @param string $name 配置名 + * 加载系统配置文件,如果之前已经加载过,那么就直接返回所有配置或其中一个配置 * @param string $file 文件名 - * @return mix + * @param string $name 配置名 + * @return mixed 找不到配置时返回false,当$name为空时返回文件所有配置,否则只返回$name这配置项 */ - static public function get($name,$file='conf') + static public function get($file='conf', $name=null) { - if(isset(self::$conf[$file][$name])) { - return self::$conf[$file][$name]; - } else { - $conf = CORE.'config/'.$file.'.php'; - if(is_file($conf)) { - self::$conf[$file] = include $conf; - return isset(self::$conf[$file][$name])?self::$conf[$file][$name]:false; - } else { + // 判断配置没有缓存的话就导入配置文件并缓存 + if (!isset(self::$conf[$file])) + // 判断配置文件是否存在 + $conf = CORE.'config/' . $file . '.php'; + if (!is_file($conf)) { return false; } + + self::$conf[$file] = include $conf; } - } - - /** - * 加载系统配置文件(直接加载整个配置文件),如果之前已经加载过,那么就直接返回 - * @param string $name 配置名 - * @param string $file 文件名 - * @return mix - */ - static public function all($file) - { - if(isset(self::$conf[$file])) { + // 如果$name为null则返回所有的设置 + if (is_null($name)) { return self::$conf[$file]; - } else { - $conf = CORE.'config/'.$file.'.php'; - if(is_file($conf)) { - self::$conf[$file] = include $conf; - return self::$conf[$file]; - } else { - return false; - } } + // 判断配置项是否存在并返回 + return isset(self::$conf[$file][$name]) ? self::$conf[$file][$name] : false; } -} \ No newline at end of file diff --git a/core/ppphp/route.php b/core/ppphp/route.php index 4bcadd8..2bf84e7 100755 --- a/core/ppphp/route.php +++ b/core/ppphp/route.php @@ -13,7 +13,7 @@ class route public $route; public function __construct() { - $route = conf::all('route'); + $route = conf::get('route'); if(isset($_SERVER['REQUEST_URI'])) { $pathstr = str_replace($_SERVER['SCRIPT_NAME'],'',$_SERVER['REQUEST_URI']); //丢掉?以及后面的参数 @@ -56,8 +56,8 @@ public function __construct() } } else { - $this->ctrl = conf::get('DEFAULT_CTRL','route'); - $this->action = conf::get('DEFAULT_ACTION','route'); + $this->ctrl = conf::get('route', 'DEFAULT_CTRL'); + $this->action = conf::get('route', 'DEFAULT_ACTION'); } } @@ -69,4 +69,4 @@ public function urlVar($num,$default = false) return $default; } } -} \ No newline at end of file +}