535b41175c675adcdf7e7e71a9f06dc339f662c5.svn-base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php namespace Maze\Config;
  2. use Maze\Http\Url;
  3. class Project
  4. {
  5. /**
  6. * content
  7. *
  8. * @var array
  9. */
  10. static private $content;
  11. /**
  12. * alias
  13. *
  14. * @var array
  15. */
  16. static private $alias;
  17. /**
  18. * content
  19. *
  20. * @return mixed
  21. */
  22. static public function content($update = false)
  23. {
  24. $file = MAZE_PATH . 'data/project/' . (defined('MAZE_PROJECT') ? MAZE_PROJECT : 'default') . '.php';
  25. if(self::$content && $update == false)
  26. {
  27. return $file;
  28. }
  29. self::$content = array();
  30. if(is_file($file))
  31. {
  32. require $file;
  33. self::$content = $project;
  34. self::$alias = $alias;
  35. }
  36. return $file;
  37. }
  38. /**
  39. * register project file
  40. *
  41. * @return mixed
  42. */
  43. static public function register()
  44. {
  45. $file = self::content();
  46. if(empty(self::$content[MAZE_PROJECT_NAME]))
  47. {
  48. self::$content[MAZE_PROJECT_NAME] = array
  49. (
  50. 'name' => MAZE_PROJECT_NAME,
  51. 'path' => MAZE_PROJECT_PATH,
  52. 'url' => Url::get(''),
  53. 'lang' => defined('MAZE_PROJECT_LANG') ? MAZE_PROJECT_LANG : MAZE_PROJECT_NAME,
  54. 'order' => defined('MAZE_PROJECT_ORDER') ? MAZE_PROJECT_ORDER : 1,
  55. 'lib' => defined('MAZE_PROJECT_LIB') ? MAZE_PROJECT_LIB : MAZE_PROJECT_NAME
  56. );
  57. foreach(self::$content as $k => $v)
  58. {
  59. if($v['lib'] != $k)
  60. {
  61. self::$alias[$v['lib']] = '$project["'.$k.'"]';
  62. }
  63. }
  64. $alias = array();
  65. if(self::$alias)
  66. {
  67. $alias = str_replace(array("'$", "',"), array("$", ","), var_export(self::$alias, true));
  68. }
  69. else
  70. {
  71. $alias = var_export(self::$alias, true);
  72. }
  73. file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';$alias = ' . $alias . ';');
  74. # 加入后台菜单
  75. if(self::load('manage'))
  76. {
  77. //\Maze\Routing\Load::get('manage/menu.load');
  78. }
  79. }
  80. elseif(isset(self::$content[MAZE_PROJECT_NAME]) && self::$content[MAZE_PROJECT_NAME]['path'] != MAZE_PROJECT_PATH)
  81. {
  82. self::update(MAZE_PROJECT_NAME, 'path', MAZE_PROJECT_PATH);
  83. self::content(true);
  84. //\Maze\Http\Output::abert('project_already_exists', MAZE_PROJECT_NAME);
  85. }
  86. }
  87. /**
  88. * update project content
  89. *
  90. * @return mixed
  91. */
  92. static public function update($key, $index, $value)
  93. {
  94. $file = self::content();
  95. if(isset(self::$content[$key]))
  96. {
  97. self::$content[$key][$index] = $value;
  98. file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';');
  99. }
  100. }
  101. /**
  102. * read
  103. *
  104. * @return mixed
  105. */
  106. static public function read()
  107. {
  108. return self::$content;
  109. }
  110. /**
  111. * load
  112. *
  113. * @return mixed
  114. */
  115. static public function load($project)
  116. {
  117. if(isset(self::$content[$project]))
  118. {
  119. return self::$content[$project];
  120. }
  121. elseif(isset(self::$alias[$project]))
  122. {
  123. return self::$alias[$project];
  124. }
  125. return false;
  126. }
  127. }