예제 #1
0
 /**
  * 获取接口数据
  * @access public
  * param string $query 查询条件
  * @return array
  */
 public function pull($query)
 {
     //获取数据缓存
     if ($this->Is_Open_Cache == TRUE) {
         $result = $this->_getDataCache($query);
     }
     if ($result == XF_CACHE_EMPTY || $this->Is_Open_Cache == FALSE) {
         $st = microtime(true);
         //$url = urlencode($query);
         $url = self::_webapi_domain . $query;
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_USERAGENT);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
         curl_setopt($curl, CURLOPT_TIMEOUT, 30);
         $response = curl_exec($curl);
         curl_close($curl);
         $json = json_decode($response);
         if (is_object($json)) {
             if ($this->Is_Open_Cache == TRUE) {
                 $this->_setDataCache($result, $query);
                 //设置数据缓存
             }
             XF_DataPool::getInstance()->addList('Load_Interface', $query . ' ' . sprintf('%.5fs', microtime(true) - $st));
             return $json;
         } else {
             $message = '接口获取数据失败';
             XF_Functions::writeErrLog($message);
         }
     } else {
         return $result;
     }
 }
예제 #2
0
파일: Front.php 프로젝트: kevinwan/xf
 /**
  * 转发控制器
  * @param XF_Controller_Request_Abstract $request
  * @param bool $runRouter 重新运行路由解析 默认为true
  * @throws XF_Controller_Exception
  */
 private function _dispatch(XF_Controller_Request_Abstract $request = null, $runRouter = true)
 {
     $this->_dispath_count++;
     if ($request != null) {
         $this->_request = $request;
     }
     if ($this->_dispath_count == 1) {
         $this->_plugin_manage->routeStartup($this->_request);
         $this->_router->run();
         $this->_plugin_manage->routeShutdown($this->_request);
     } elseif ($this->_dispath_count >= 5) {
         XF_Functions::writeErrLog('URI:' . $this->_request->getRequestUrl() . ' - loop forever dispatch controller');
         throw new XF_Exception('loop forever dispatch controller');
     } else {
         if ($runRouter == true) {
             $this->_router->run();
         }
     }
     //没有找到正确的模块
     if ($this->_request->getModule() == 'unknown') {
         throw new XF_Exception('404 Not found!', 404);
     }
     //加载控制器
     $this->getModuleDir();
     $controllerName = NULL;
     if (strtolower($this->_request->getModule()) != 'default') {
         $controllerName = ucfirst($this->_request->getModule()) . '_';
     }
     $this->_controller_dir = $this->_module_dir . '/controllers';
     $controllerFile = $this->_controller_dir . '/' . ucfirst($this->_request->getController()) . 'Controller.php';
     if (is_file($controllerFile)) {
         require_once $controllerFile;
         $controllerName .= ucfirst($this->_request->getController()) . 'Controller';
         if (class_exists($controllerName, FALSE)) {
             $this->_plugin_manage->preDispatch($this->_request);
             $this->_controller_instance = new $controllerName();
             $this->_plugin_manage->postDispatch($this->_request);
         }
     }
     if ($this->_controller_instance == null) {
         throw new XF_Exception('404 Not found!', 404);
     } elseif ($this->_controller_instance instanceof XF_Controller_Interface) {
         $this->_controller_instance->doAction();
     } else {
         throw new XF_Exception('404 Not found!', 404);
     }
 }
예제 #3
0
파일: Application.php 프로젝트: kevinwan/xf
 /**
  * 全局异常处理
  * @param Exception $e
  * @throws Exception
  * @throws XF_Exception
  */
 public static function appException(Exception $e)
 {
     $req = XF_Controller_Request_Http::getInstance();
     $message = $req->getMethod() . ' "' . $req->getRequestUrl() . '" ' . $e->getMessage() . "\n";
     XF_Functions::writeErrLog($message . $e->getTraceAsString());
     echo $e;
 }