public function run() { try { $response = $this->tryRun(); } catch (\Exception $ex) { $response = new \Zend\Http\Response(); $code = $ex->getCode(); if (is_numeric($code) && $code >= 200 && $code <= 500) { $response->setStatusCode($code); } else { $response->setStatusCode(500); } $response->getHeaders()->addHeaderLine('Content-Type', 'application/json'); $response->setContent(\json_encode(array('exception' => get_class($ex), 'message' => $ex->getMessage()))); } $response->getHeaders()->addHeaderLine('Access-Control-Allow-Origin', '*'); /** * Imprime a resposta */ $status = $response->renderStatusLine(); header($status); foreach ($response->getHeaders() as $header) { if ($header instanceof MultipleHeaderInterface) { header($header->toString(), false); continue; } header($header->toString()); } echo $response->getContent(); }