示例#1
0
文件: Api.php 项目: rozza/genghis
 public function run()
 {
     try {
         return parent::run();
     } catch (Genghis_HttpException $e) {
         $msg = $e->getMessage() ? $e->getMessage() : Genghis_Response::getStatusText($e->getStatus());
         $response = new Genghis_JsonResponse(array('error' => $msg), $e->getStatus());
         $response->render();
     }
 }
示例#2
0
 public function route($method, $path)
 {
     if ($this->isJsonRequest()) {
         try {
             $api = new Genghis_Api();
             return $api->route($method, $path);
         } catch (Genghis_HttpException $e) {
             $msg = $e->getMessage() ? $e->getMessage() : Genghis_Response::getStatusText($e->getStatus());
             return new Genghis_JsonResponse(array('error' => $msg, 'status' => $e->getStatus()), $e->getStatus());
         }
     } else {
         if (strpos($path, '/assets/') === 0) {
             return $this->getAsset(substr($path, 8));
         } else {
             // not an api request, we'll return index.html and render the page in javascript.
             return $this->renderTemplate('index.html.mustache');
         }
         break;
     }
 }
示例#3
0
 public function __construct($status = 500, $msg = '')
 {
     $this->status = $status;
     parent::__construct(empty($msg) ? Genghis_Response::getStatusText($status) : $msg);
 }