示例#1
0
文件: Header.php 项目: rudraks/core
 public static function scan()
 {
     Browser::warn("Scanning All Web Modules");
     ResourceUtil::$RESOURCE_DIST_DIR = "resources_cache";
     // READ MODULES
     self::$webmodules = self::getModuleProperties(LIB_PATH, self::$webmodules);
     self::$webmodules = self::getModuleProperties(RESOURCE_PATH, self::$webmodules);
     self::$cache->set('webmodules', self::$webmodules);
     // CREATE MODULE FILES
     self::$modulefiles = array();
     $header = new Header();
     if (!empty(self::$webmodules['bundles'])) {
         foreach (self::$webmodules['bundles'] as $module => $moduleObject) {
             $header->_import($module);
         }
     }
     $header->minify();
     self::$cache->set('modulefiles', self::$modulefiles);
     self::$cache->save();
     FileUtil::build_write(self::$BUNDLE_PATH, json_encode(Header::getModules()));
     Browser::info(self::$webmodules, self::$modulefiles);
 }
示例#2
0
 public static function scan_modules($dirs = array("lib", "resources"), $target = "resources/bundle.json")
 {
     self::$webmodules = array("_" => array(), "bundles" => array());
     foreach ($dirs as $dir) {
         self::$webmodules = self::scan_modules_dir(self::$PROJECT_ROOT_DIR . $dir, self::$webmodules);
     }
     FileUtil::build_mkdir(self::$RESOURCE_DIST_DIR);
     FileUtil::build_write(self::$RESOURCE_DIST_DIR . "/" . $target, json_encode(self::$webmodules, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     FileUtil::build_export_object(self::$RESOURCE_DIST_DIR . "/" . $target . ".php", self::$webmodules);
     return self::$webmodules;
 }
示例#3
0
 public function _interpret_($info, $params)
 {
     $nocache = isset($_REQUEST["_AUTH_"]) || isset($_REQUEST["_NOCACHE_"]);
     $cache = $info["cache"] && !$nocache;
     $cache_file = $info["cache"] === "file" && !empty(Webapp::$REQUEST_FILE_EXT);
     $perform = true;
     $md5key = null;
     $validate = $this->user->validate();
     if ($info["auth"] && !$validate) {
         $this->user->basicAuth();
     }
     if ($info["roles"] !== FALSE) {
         if (!in_array($this->user->role, $info["roles"])) {
             print_r($info["roles"]);
             echo $this->user->role;
             header("HTTP/1.1 403 Unauthorized");
             exit;
         }
     }
     $cache = ($cache || isset($info["guestcache"]) && $info["guestcache"] && !$validate) && !$nocache;
     header("Pragma:");
     header("X-Rudrax-Authd: false");
     if ($cache && !$cache_file) {
         header("X-Rudrax-Enabled: true");
         $this->responseCache = new RxCache('responseCache');
         $this->headerCache = new RxCache('headerCache');
         if (defined("RX_RESP_CACHE_TIME")) {
             $this->cacheDuration = RX_RESP_CACHE_TIME;
         } else {
             $this->cacheDuration = 900;
             // in seconds
         }
         // Client is told to cache these results for set duration
         header('Cache-Control: public,max-age=' . $this->cacheDuration . ',must-revalidate');
         header('Expires: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $this->cacheDuration) . ' GMT');
         header('Last-modified: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME']) . ' GMT');
         // Pragma header removed should the server happen to set it automatically
         // Pragma headers can make browser misbehave and still ask data from server
         header_remove('Pragma');
         $md5key = md5($_SERVER["REQUEST_URI"]);
         $response = $this->responseCache->get($md5key, FALSE);
         if (!empty($response)) {
             $perform = false;
             echo $response;
             $headerstr = $this->headerCache->get($md5key);
             $headers = explode(self::$HEADER_GLUE, $headerstr);
             foreach ($headers as $header) {
                 header($header);
             }
             header("X-Rudrax-Cached: true");
             if ($validate) {
                 header("X-Rudrax-Authd: true");
             }
             exit;
         } else {
             if ($validate) {
                 header("X-Rudrax-Authd: true");
             }
             // ob_start('ob_gzhandler');
         }
     }
     if ($perform) {
         $this->_interceptor_($info, $params);
     }
     if ($perform && $cache) {
         $response = ob_get_contents();
         if ($cache_file === true) {
             FileUtil::build_write("/cache_file/" . Webapp::$REQUEST_PATHNAME, $response);
         } else {
             $this->responseCache->set($md5key, $response);
             $this->headerCache->set($md5key, implode(self::$HEADER_GLUE, headers_list()));
         }
         // ob_end_flush();
         // echo $response;
     }
 }