private function setDefaultResponseAsJSON() { $this->after(function () { /// Results returned from the route's controller. All Controllers should return an array $records = $this->getReturnedValue(); $response = new JSONResponse(); $response->useEnvelope(true)->convertSnakeCase(true)->send($records); }); }
public function send() { $di = 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 JSONResponse(); $response->send($error, true); return; } error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine()); return true; }