示例#1
0
 function _initDebug(Dispatcher $dispatcher)
 {
     $debug = (bool) $dispatcher->getApplication()->getConfig()->debug;
     if ($debug) {
         new Debug();
     }
     Error::error2exception();
 }
示例#2
0
 private function indexAction()
 {
     $startTime = microtime(true);
     $request = $this->getRequest();
     $module = $request->getParam('module');
     $version = $request->getParam('version');
     $method = $request->getParam('method');
     $responseFormat = $request->getParam('responseFormat');
     $param = array();
     $param['request'] = $request->getRequest();
     $param['query'] = $request->getQuery();
     $param['post'] = $request->getPost();
     $param['cookie'] = $request->getCookie();
     $param['input'] = file_get_contents('php://input');
     $api = ApiModel::getInstance($module, $version, $method, $param, $responseFormat);
     $value = null;
     try {
         $value = $api->call();
         $res = $api->getResponse(ApiException::ERROR_OK, 'ok', $value, $startTime);
     } catch (\Exception $exception) {
         $errorLog = ini_get('error_log');
         $logErrors = ini_get('log_errors');
         $displayErrors = ini_get('display_errors');
         $message = $exception->getMessage();
         if ($exception instanceof ApiException) {
             ini_set('log_errors', false);
             ini_set('display_errors', false);
             $value = $exception->getValue();
         } else {
             ini_set('error_log', dirname($errorLog) . '/php_exception.log');
             $url = \Ares333\YafLib\Helper\Http::getUrl('current');
             $exception = new ApiException($url, ApiException::ERROR_SERVER, $exception);
         }
         Error::catchException($exception);
         $res = $api->getResponse($exception->getCode(), $message, $value, $startTime);
         ini_set('error_log', $errorLog);
         ini_set('log_errors', $logErrors);
         ini_set('display_errors', $displayErrors);
     }
     $this->getResponse()->clearHeaders('Content-Type');
     $this->getResponse()->appendBody($res, 'api');
     $this->log();
     return false;
 }