123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php namespace Maze\Config;
- class Load
- {
- /**
- * global
- *
- * @var array
- */
- static public $global;
- /**
- * object
- *
- * @var object
- */
- static public $object;
- /**
- * get
- * @param string $file
- * @param string $path
- * @param string $project
- *
- * @return mixed
- */
- static public function get($file = 'host', $project = '', $path = 'config')
- {
- if($project)
- {
- $index = $project . '_' . $path . '_' . $file;
- }
- else
- {
- $index = $file;
- }
- if(empty(self::$global[$index]))
- {
- /* 暂时取消对data的读取
- $project = $project ? $project : MAZE_PROJECT_NAME;
- $config = array(MAZE_PATH, MAZE_PROJECT_PATH, MAZE_PATH . 'data/' . $project . '/');
- */
- # 增加对project的读取
- if($project)
- {
- $project = Project::load($project);
- }
- $root = isset($project['path']) ? $project['path'] : MAZE_PROJECT_PATH;
- $config = array(MAZE_PATH, $root);
- self::$global[$index] = array();
- self::file($file, $path);
- foreach($config as $k => $v)
- {
- self::assign($v . $path, $index);
- }
- if($file != $index)
- {
- self::$global[$file] = self::$global[$index];
- }
- }
-
- return self::$global[$index];
- }
- /**
- * object
- * @param string $file
- *
- * @var array
- */
- static private function object($file, $project = '', $path = 'config')
- {
- if($project)
- {
- $index = $project . '_' . $path . '_' . $file;
- }
- else
- {
- $index = $file;
- }
- if(isset(self::$object[$index]))
- {
- return self::$object[$index];
- }
- self::$object[$index] = (object) self::$global[$index];
- if($file != $index)
- {
- self::$object[$file] = self::$object[$index];
- }
- return self::$object[$index];
- }
- /**
- * file
- * @param string $file
- * @param string $path
- *
- * @var array
- */
- static private function file($file, &$path)
- {
- $path .= '/';
- if($file == 'host' || $file == 'database' || $file == 'debug')
- {
- $path .= $_SERVER['MAZEPHP_SERVER'] . '/';
- }
- $path .= $file . '.php';
- }
- /**
- * assign
- * @param string $file
- *
- * @var array
- */
- static private function assign($file, $index)
- {
- if(is_file($file))
- {
- $config = include($file);
-
- if(is_array($config))
- {
- self::$global[$index] = array_merge(self::$global[$index], $config);
- }
- }
- }
- }
|