1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php namespace Dever;
- class Project
- {
- protected static $content = array();
- public static function init()
- {
- $file = File::get('app.php');
- if (!self::$content) {
- if (is_file($file)) {
- require $file;
- self::$content = $project;
- }
- if (isset(Config::get('setting')['app'])) {
- self::$content = array_merge(self::$content, Config::get('setting')['app']);
- }
- }
- return $file;
- }
- public static function register()
- {
- $file = self::init();
- if (empty(self::$content[DEVER_APP_NAME])) {
- $host = DEVER_APP_HOST;
- if (strpos($host, '/src/' . DEVER_APP_NAME)) {
- $host = explode('/src/' . DEVER_APP_NAME, $host)[0] . '/';
- } elseif (strpos($host, '/app/' . DEVER_APP_NAME)) {
- $host = explode('/app/' . DEVER_APP_NAME, $host)[0] . '/';
- }elseif (strpos($host, '/package/' . DEVER_APP_NAME)) {
- $host = explode('/package/' . DEVER_APP_NAME, $host)[0] . '/';
- }
- self::write($host, 'package');self::write($host, 'src');self::write($host, 'app');
- self::$content[DEVER_APP_NAME]['url'] = DEVER_APP_HOST;
- if (isset(self::$content['manage'])) {
- $manage = self::$content['manage'];
- unset(self::$content['manage']);
- self::$content = array_merge(array('manage' => $manage), self::$content);
- }
- self::content($file);
- if (isset(self::$content['manage'])) {
- \Dever::load('menu', 'manage')->init();
- }
- }
- if (empty(self::$content[DEVER_APP_NAME]['lang'])) {
- self::$content[DEVER_APP_NAME]['lang'] = DEVER_APP_LANG;
- self::content($file);
- }
- }
- public static function write($host, $name)
- {
- $dir = DEVER_PROJECT_PATH . $name . '/';
- if (is_dir($dir)) {
- $data = scandir($dir);
- foreach ($data as $v) {
- if (empty(self::$content[$v]) && is_dir($dir . '/' . $v) && $v !== '.' && $v !== '..') {
- if (is_file($dir . $v . '/index.php')) {
- $k = $name . '/' . $v . '/';
- self::$content[$v] = array();
- if (strstr($name, 'package')) {
- if (strstr($name, 'package/manage')) {
- unset(self::$content[$v]);
- $v = 'manage';
- self::$content[$v] = array();
- self::$content[$v]['path'] = DEVER_PATH . $name . '/';
- } elseif($v == 'manage') {
- self::$content[$v]['path'] = DEVER_PATH . $k;
- $k .= 'api/';
- } else {
- self::$content[$v]['path'] = DEVER_PATH . $k;
- }
- self::$content[$v]['setup'] = DEVER_PROJECT_PATH . $k;
- } else {
- self::$content[$v]['path'] = DEVER_PROJECT_PATH . $k;
- }
- self::$content[$v]['url'] = $host . $k;
- } else {
- self::write($host, $name . '/' . $v);
- }
- }
- }
- }
- }
- public static function content($file)
- {
- file_put_contents($file, '<?php $project = ' . var_export(self::$content, true) . ';');
- }
- public static function read()
- {
- return self::$content;
- }
- public static function load($app)
- {
- if (isset(self::$content[$app])) {
- return self::$content[$app];
- }
- return false;
- //Output::error('app not exists:' . $app);
- }
- }
|