Project.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php namespace Dever;
  2. class Project
  3. {
  4. protected static $content = array();
  5. public static function init()
  6. {
  7. $file = File::get('app.php');
  8. if (!self::$content) {
  9. if (is_file($file)) {
  10. require $file;
  11. self::$content = $project;
  12. }
  13. if (isset(Config::get('setting')['app'])) {
  14. self::$content = array_merge(self::$content, Config::get('setting')['app']);
  15. }
  16. }
  17. return $file;
  18. }
  19. public static function register()
  20. {
  21. $file = self::init();
  22. if (empty(self::$content[DEVER_APP_NAME])) {
  23. $host = DEVER_APP_HOST;
  24. if (strpos($host, '/src/' . DEVER_APP_NAME)) {
  25. $host = explode('/src/' . DEVER_APP_NAME, $host)[0] . '/';
  26. } elseif (strpos($host, '/app/' . DEVER_APP_NAME)) {
  27. $host = explode('/app/' . DEVER_APP_NAME, $host)[0] . '/';
  28. }elseif (strpos($host, '/package/' . DEVER_APP_NAME)) {
  29. $host = explode('/package/' . DEVER_APP_NAME, $host)[0] . '/';
  30. }
  31. self::write($host, 'package');self::write($host, 'src');self::write($host, 'app');
  32. self::$content[DEVER_APP_NAME]['url'] = DEVER_APP_HOST;
  33. if (isset(self::$content['manage'])) {
  34. $manage = self::$content['manage'];
  35. unset(self::$content['manage']);
  36. self::$content = array_merge(array('manage' => $manage), self::$content);
  37. }
  38. self::content($file);
  39. if (isset(self::$content['manage'])) {
  40. \Dever::load('menu', 'manage')->init();
  41. }
  42. }
  43. if (empty(self::$content[DEVER_APP_NAME]['lang'])) {
  44. self::$content[DEVER_APP_NAME]['lang'] = DEVER_APP_LANG;
  45. self::content($file);
  46. }
  47. }
  48. public static function write($host, $name)
  49. {
  50. $dir = DEVER_PROJECT_PATH . $name . '/';
  51. if (is_dir($dir)) {
  52. $data = scandir($dir);
  53. foreach ($data as $v) {
  54. if (empty(self::$content[$v]) && is_dir($dir . '/' . $v) && $v !== '.' && $v !== '..') {
  55. if (is_file($dir . $v . '/index.php')) {
  56. $k = $name . '/' . $v . '/';
  57. self::$content[$v] = array();
  58. if (strstr($name, 'package')) {
  59. if (strstr($name, 'package/manage')) {
  60. unset(self::$content[$v]);
  61. $v = 'manage';
  62. self::$content[$v] = array();
  63. self::$content[$v]['path'] = DEVER_PATH . $name . '/';
  64. } elseif($v == 'manage') {
  65. self::$content[$v]['path'] = DEVER_PATH . $k;
  66. $k .= 'api/';
  67. } else {
  68. self::$content[$v]['path'] = DEVER_PATH . $k;
  69. }
  70. self::$content[$v]['setup'] = DEVER_PROJECT_PATH . $k;
  71. } else {
  72. self::$content[$v]['path'] = DEVER_PROJECT_PATH . $k;
  73. }
  74. self::$content[$v]['url'] = $host . $k;
  75. } else {
  76. self::write($host, $name . '/' . $v);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. public static function content($file)
  83. {
  84. file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';');
  85. }
  86. public static function read()
  87. {
  88. return self::$content;
  89. }
  90. public static function load($app)
  91. {
  92. if (isset(self::$content[$app])) {
  93. return self::$content[$app];
  94. }
  95. return false;
  96. //Output::error('app not exists:' . $app);
  97. }
  98. }