b6481dec74835881b8a9792336dd6cf50b3bf79b.svn-base 2.5 KB

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