示例#1
0
 public function _interpret_($info, $params)
 {
     $cache = $info["cache"];
     $perform = true;
     $md5key = null;
     if ($cache) {
         $this->responseCache = new RxCache('responseCache');
         $this->headerCache = new RxCache('headerCache');
         $this->cacheDuration = 300;
         // 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);
             }
             Browser::header("fromCahce");
             exit;
         } else {
             // ob_start('ob_gzhandler');
         }
     }
     if ($perform) {
         $this->_interceptor_($info, call_method_by_object($this, $info["method"], $params, $info["requestParams"]));
     }
     if ($perform && $cache) {
         $response = ob_get_contents();
         $this->responseCache->set($md5key, $response);
         $this->headerCache->set($md5key, implode(self::$HEADER_GLUE, headers_list()));
         // ob_end_flush();
         // echo $response;
     }
 }
示例#2
0
 public function _interceptor_($info, $params)
 {
     if (!isset($info["type"])) {
         $info["type"] = "data";
     }
     if (isset($info["type"])) {
         $controller = $this;
         return call_user_func(rx_function("rx_interceptor_" . $info["type"]), $this->user, $info, $params, function ($newParams) use($controller, $info, $params) {
             try {
                 $dontPrevent = true;
                 if (method_exists($controller, "_before_controller_")) {
                     $dontPrevent = !!call_method_by_object($controller, "_before_controller_", $newParams, $info["requestParams"]);
                 }
                 $returned = null;
                 if ($dontPrevent) {
                     $returned = call_method_by_object($controller, $info["method"], $newParams, $info["requestParams"]);
                     if (method_exists($controller, "_post_controller_")) {
                         $returned = call_method_by_object($controller, "_post_controller_", $newParams, $info["requestParams"]);
                     }
                     return $returned;
                 }
             } catch (\Exception $e) {
                 if (function_exists("controller_exception_handler")) {
                     controller_exception_handler($e);
                 } else {
                     print_line("<div style='display:none'>**============**");
                     print_line("Controller Exception:" . $e->getMessage());
                     print_line("**--------------**");
                     print_line($e->getTraceAsString());
                     print_line("**============**</div>");
                 }
             }
             return "empty";
         });
     }
 }