Example #1
0
File: Core.php Project: iamfat/gini
 /**
  * Fetch module info from provided path.
  *
  * (object) info
  *     ->id
  *     ->path
  *     ->name
  *     ->description
  *     ->version
  *     ->dependencies
  *     ->build
  *
  * @param string $path Module path
  *
  * @return object|false Module info
  **/
 public static function fetchModuleInfo($path)
 {
     /*
     $id; $path;
     $name; $description; $version;
     $dependencies;
     */
     if ($path[0] != '/' && $path[0] != '.') {
         // 相对路径
         $npath = getcwd() . '/modules/' . $path;
         $path = is_dir($npath) ? $npath : $_SERVER['GINI_MODULE_BASE_PATH'] . '/' . $path;
     }
     // $path = realpath($path);
     $info_script = $path . '/gini.json';
     if (!file_exists($info_script)) {
         return false;
     }
     $info = (object) @json_decode(@file_get_contents($info_script), true);
     if (!is_array($info->dependencies)) {
         $info->dependencies = [];
     }
     if (!$info->id) {
         $info->id = \Gini\File::relativePath($path, $_SERVER['GINI_MODULE_BASE_PATH']);
     }
     if ($info->id != 'gini' && !isset($info->dependencies['gini'])) {
         $info->dependencies['gini'] = '*';
     }
     $info->path = $path;
     return $info;
 }
Example #2
0
File: App.php Project: iamfat/gini
 public function actionModules($args)
 {
     foreach (\Gini\Core::$MODULE_INFO as $name => $info) {
         if (!$info->error) {
             $rPath = \Gini\File::relativePath($info->path, APP_PATH);
             if ($rPath[0] == '.') {
                 $rPath = \Gini\File::relativePath($info->path, dirname(SYS_PATH));
                 if ($rPath[0] == '.') {
                     $rPath = '@/' . \Gini\File::relativePath($info->path, $_SERVER['GINI_MODULE_BASE_PATH']);
                 } else {
                     $rPath = '!/' . $rPath;
                 }
             }
         }
         printf("%s %s %s %s %s\n", $info->error ? "" : '', $this->_strPad($name, 30, ' '), $this->_strPad($info->version, 15, ' '), $this->_strPad($info->name, 30, ' '), $info->error ?: $rPath);
     }
 }
Example #3
0
 public static function exception($e)
 {
     $message = $e->getMessage();
     $file = $e->getFile();
     foreach (\Gini\Core::$MODULE_INFO as $info) {
         if (0 == strncmp($file, $info->path, strlen($info->path))) {
             $file = "[{$info->id}] " . \Gini\File::relativePath($file, $info->path);
             break;
         }
     }
     $line = $e->getLine();
     printf("[E] %s\n", $message);
     error_log(sprintf('[E] %s (%s:%d)', $message, $file, $line));
     $trace = array_slice($e->getTrace(), 1, 3);
     foreach ($trace as $n => $t) {
         $file = $t['file'];
         foreach (\Gini\Core::$MODULE_INFO as $info) {
             if (0 == strncmp($file, $info->path, strlen($info->path))) {
                 $file = "[{$info->id}] " . \Gini\File::relativePath($file, $info->path);
                 break;
             }
         }
         error_log(sprintf('%3d. %s%s() in (%s:%d)', $n + 1, $t['class'] ? $t['class'] . '::' : '', $t['function'], $file, $t['line']));
     }
 }
Example #4
0
 public static function exception($e)
 {
     $message = $e->getMessage();
     if ($message) {
         $file = $e->getFile();
         foreach (\Gini\Core::$MODULE_INFO as $info) {
             if (0 == strncmp($file, $info->path, strlen($info->path))) {
                 $file = "[{$info->id}] " . \Gini\File::relativePath($file, $info->path);
                 break;
             }
         }
         $line = $e->getLine();
         error_log(sprintf('ERROR %s', $message));
         $trace = array_slice($e->getTrace(), 1, 5);
         foreach ($trace as $n => $t) {
             $file = $t['file'];
             foreach (\Gini\Core::$MODULE_INFO as $info) {
                 if (0 == strncmp($file, $info->path, strlen($info->path))) {
                     $file = "[{$info->id}] " . \Gini\File::relativePath($file, $info->path);
                     break;
                 }
             }
             error_log(sprintf('    %d) %s%s() in %s on line %d', $n + 1, $t['class'] ? $t['class'] . '::' : '', $t['function'], $file, $t['line']));
         }
     }
     if (PHP_SAPI != 'cli') {
         while (@ob_end_clean()) {
         }
         //清空之前的所有显示
         header('HTTP/1.1 500 Internal Server Error');
     }
 }