コード例 #1
0
 public function send()
 {
     $di = \Phalcon\DI::getDefault();
     $res = $di->get('response');
     $req = $di->get('request');
     //query string, filter, default
     if (!$req->get('suppress_response_codes', null, null)) {
         $res->setStatusCode($this->getCode(), $this->response)->sendHeaders();
     } else {
         $res->setStatusCode('200', 'OK')->sendHeaders();
     }
     $error = array('errorCode' => $this->getCode(), 'userMessage' => $this->getMessage(), 'devMessage' => $this->devMessage, 'more' => $this->additionalInfo, 'applicationCode' => $this->errorCode);
     if (!$req->get('type') || $req->get('type') == 'json') {
         $response = new \PhalconRest\Responses\JSONResponse();
         $response->send($error, true);
         return;
     } else {
         if ($req->get('type') == 'csv') {
             $response = new \PhalconRest\Responses\CSVResponse();
             $response->send(array($error));
             return;
         }
     }
     error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
     return true;
 }
コード例 #2
0
    if ($app->request->getMethod() == 'OPTIONS') {
        $app->response->setStatusCode('200', 'OK');
        $app->response->send();
        return;
    }
    // Respond by default as JSON
    if (!$app->request->get('type') || $app->request->get('type') == 'json') {
        // Results returned from the route's controller.  All Controllers should return an array
        $records = $app->getReturnedValue();
        $response = new \PhalconRest\Responses\JSONResponse();
        $response->useEnvelope(true)->convertSnakeCase(true)->send($records);
        return;
    } else {
        if ($app->request->get('type') == 'csv') {
            $records = $app->getReturnedValue();
            $response = new \PhalconRest\Responses\CSVResponse();
            $response->useHeaderRow(true)->send($records);
            return;
        } else {
            throw new \PhalconRest\Exceptions\HTTPException('Could not return results in specified format', 403, array('dev' => 'Could not understand type specified by type paramter in query string.', 'internalCode' => 'NF1000', 'more' => 'Type may not be implemented. Choose either "csv" or "json"'));
        }
    }
});
/**
 * The notFound service is the default handler function that runs when no route was matched.
 * We set a 404 here unless there's a suppress error codes.
 */
$app->notFound(function () use($app) {
    throw new \PhalconRest\Exceptions\HTTPException('Not Found.', 404, array('dev' => 'That route was not found on the server.', 'internalCode' => 'NF1000', 'more' => 'Check route for mispellings.'));
});
/**