123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php namespace Maze\Config;
- use Maze\Http\Url;
- class Project
- {
- /**
- * content
- *
- * @var array
- */
- static private $content;
- /**
- * alias
- *
- * @var array
- */
- static private $alias;
- /**
- * content
- *
- * @return mixed
- */
- static public function content()
- {
- $file = MAZE_PATH . 'data/project/' . (defined('MAZE_PROJECT') ? MAZE_PROJECT : 'default') . '.php';
- self::$content = array();
- if(is_file($file))
- {
- require $file;
- self::$content = $project;
- self::$alias = $alias;
- }
- return $file;
- }
-
- /**
- * register project file
- *
- * @return mixed
- */
- static public function register()
- {
- $file = self::content();
- if(empty(self::$content[MAZE_PROJECT_NAME]))
- {
- self::$content[MAZE_PROJECT_NAME] = array
- (
- 'name' => MAZE_PROJECT_NAME,
- 'path' => MAZE_PROJECT_PATH,
- 'url' => Url::get(''),
- 'lang' => defined('MAZE_PROJECT_LANG') ? MAZE_PROJECT_LANG : MAZE_PROJECT_NAME,
- 'order' => defined('MAZE_PROJECT_ORDER') ? MAZE_PROJECT_ORDER : 1,
- 'lib' => defined('MAZE_PROJECT_LIB') ? MAZE_PROJECT_LIB : MAZE_PROJECT_NAME
- );
- foreach(self::$content as $k => $v)
- {
- if($v['lib'] != $k)
- {
- self::$alias[$v['lib']] = '$project["'.$k.'"]';
- }
- }
- $alias = array();
- if(self::$alias)
- {
- $alias = str_replace(array("'$", "',"), array("$", ","), var_export(self::$alias, true));
- }
- else
- {
- $alias = var_export(self::$alias, true);
- }
- file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';$alias = ' . $alias . ';');
-
- # 加入后台菜单
- if(self::load('manage'))
- {
- //\Maze\Routing\Load::get('manage/menu.load');
- }
- }
- elseif(isset(self::$content[MAZE_PROJECT_NAME]) && self::$content[MAZE_PROJECT_NAME]['path'] != MAZE_PROJECT_PATH)
- {
- \Maze\Http\Output::abert('project_already_exists', MAZE_PROJECT_NAME);
- }
- }
- /**
- * update project content
- *
- * @return mixed
- */
- static public function update($key, $index, $value)
- {
- $file = self::content();
- if(isset(self::$content[$key]))
- {
- self::$content[$key][$index] = $value;
- file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';');
- }
- }
- /**
- * read
- *
- * @return mixed
- */
- static public function read()
- {
- return self::$content;
- }
- /**
- * load
- *
- * @return mixed
- */
- static public function load($project)
- {
- if(isset(self::$content[$project]))
- {
- return self::$content[$project];
- }
- elseif(isset(self::$alias[$project]))
- {
- return self::$alias[$project];
- }
- return false;
- }
- }
|