Example #1
0
 private static function app($repository)
 {
     if (!$repository->start("app")) {
         return;
     }
     if (is_dir(App::path("apps"))) {
         $list = array();
         foreach (File::dir(App::path("apps"), true) as $dir) {
             $bool = true;
             foreach ($list as $p) {
                 if (strpos($dir, $p) === 0) {
                     $bool = false;
                     break;
                 }
             }
             if ($bool) {
                 $package = str_replace(array(App::path("apps/"), "/"), array("", "."), $dir);
                 $info = App::info($dir);
                 if (!empty($info["name"])) {
                     $tgz_filename = $repository->tgz_path($package);
                     File::tgz($tgz_filename, $dir);
                     touch($tgz_filename, File::last_update($dir));
                     $repository->add($package, $info["name"], File::last_update($dir), $info["description"], $info["summary"]);
                     $list[] = $dir;
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * 内部函数缓存HTML
  */
 static function cacheHtml()
 {
     if (static::$cache === false) {
         return;
     }
     $uri = $_SERVER['REQUEST_URI'];
     $uri = str_replace("//", '/', $uri);
     $uri = str_replace(Route::host(), '', $uri);
     if (!$uri || $uri == '/') {
         $uri = "index";
     }
     if (static::$cacheFileName) {
         $url = WEB . "/" . static::$htmlcache . "/" . static::$cacheFileName . ".html";
     } else {
         $url = WEB . "/" . static::$htmlcache . "/" . $uri . ".html";
     }
     $url = str_replace('//', '/', $url);
     $dir = File::dir($url);
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     if (!is_writable(File::dir($dir . ".t"))) {
         throw new \Exception("静态html目录不可写:" . $dir);
     }
     return $url;
 }
Example #3
0
 /**
  * All our modules do not follow PSR-0 and classes located as they wish to, so we will have
  * to scan all files in module location and build all classes tree.
  *
  * @param string $className Class name without namespace
  * @param string $nameSpace Namespace name without class name
  * @param string $file      Variable to return path to class file location on success
  *
  * @deprecated Should be removed after all modules will be moved to PSR class naming and locating standard
  * @return bool True if class file is found
  */
 protected static function oldModule($className, $nameSpace, &$file = null)
 {
     //elapsed('++ Autoloading '.$className.' from '.$nameSpace);
     // Convert to linux path, windows will convert it automatically if necessary
     $ns = str_replace(self::NS_SEPARATOR, '/', $nameSpace);
     // Check if we have predefined namespace path definition
     if (isset(self::$moduleMap[$nameSpace])) {
         // take path from module location map
         $path = self::$moduleMap[$nameSpace];
     } else {
         // Try automatic searcher
         /** @var string[] $locations Collection of possible class locations */
         $locations = null;
         // Iterate all possible file structures
         $path = null;
         foreach (array('php', 'js', 'cms', 'social', 'commerce') as $type) {
             // Build all possible module location for backward compatibility
             $locations = array(__SAMSON_VENDOR_PATH . str_replace('samson/', 'samsonos/', $ns) . '/' . strtolower($className), __SAMSON_VENDOR_PATH . str_replace('samson/', 'samsonos/', $ns), __SAMSON_VENDOR_PATH . str_replace('samson/', 'samsonos/' . $type . '/', $ns), __SAMSON_VENDOR_PATH . str_replace('samson/', 'samsonos/' . $type . '/', $ns) . '/api', __SAMSON_VENDOR_PATH . str_replace('samson/', 'samsonos/' . $type . '_', $ns), strpos($ns, 'cms') !== false ? __SAMSON_VENDOR_PATH . 'samsonos/cms_api' : '_', strpos($ns, 'cms') !== false ? __SAMSON_VENDOR_PATH . 'samsonos/cms/api' : '_', __SAMSON_CWD__ . __SAMSON_MODEL_PATH);
             // Iterate all locations and try to find correct existing path
             foreach ($locations as $location) {
                 if (file_exists($location)) {
                     $path = $location;
                     break 2;
                 }
             }
         }
     }
     // If class not found
     if (isset($path)) {
         $path .= '/';
         // Build files tree once for each namespace
         if (!isset(self::$fileCache[$nameSpace])) {
             self::$fileCache[$nameSpace] = File::dir($path, 'php');
         }
         // Trying to find class by class name in folder files collection
         if (sizeof($files = preg_grep('/\\/' . $className . '\\.php/i', self::$fileCache[$nameSpace]))) {
             // If we have found several files matching this class
             if (sizeof($files) > 1) {
                 return e('Cannot autoload class(##), too many files matched ##', E_SAMSON_CORE_ERROR, array($className, $files));
             }
             // Return last array element as file path
             $file = end($files);
             //elapsed('  Loaded class['.$key.'] from "'.$file.'"');
             // Everything is OK
             return true;
         }
     }
     // If we are here - signal error
     //return e('Cannot autoload class(##), class file not found in ##', D_SAMSON_DEBUG, array($className,$path));
     return false;
 }
Example #4
0
 /**
  * クラス一覧を返す
  * @param boolean $libs ライブラリを含むか
  * @param boolean $in_vendor ベンダも含むか
  * @return string{} path=>name
  */
 public static function classes($libs = true, $in_vendor = false)
 {
     self::set_path();
     $class = $package = $serach_path = array();
     if ($libs && is_dir(self::$lib_path)) {
         $serach_path[] = self::$lib_path;
     }
     if ($in_vendor && is_dir(self::$vendor_path)) {
         $serach_path[] = self::$vendor_path;
     }
     foreach ($serach_path as $search) {
         foreach (File::dir($search, true) as $dir) {
             $c = basename($dir);
             if (ctype_upper($c[0]) && is_file($dir . '/' . $c . '.php')) {
                 $package[$dir] = $dir;
                 $class[str_replace('/', '.', str_replace($search . '/', '', $dir))] = basename($dir);
             }
         }
     }
     foreach ($serach_path as $search) {
         foreach (File::ls($search, true) as $f) {
             if ($f->is_class() && strpos($f->directory(), App::work()) !== 0) {
                 $bool = true;
                 foreach ($package as $p) {
                     if (strpos($f->directory(), $p) !== false) {
                         $bool = false;
                         break;
                     }
                 }
                 if ($bool) {
                     $class[substr(str_replace('/', '.', str_replace($search . '/', '', $f->fullname())), 0, -4)] = $f->oname();
                 }
             }
         }
     }
     return $class;
 }