/** * Nette render default method * * @return void */ public function renderDefault() { $start = microtime(true); $this->sendCorsHeaders(); $hand = $this->getHandler(); $handler = $hand['handler']; $authorization = $hand['authorization']; if ($this->checkAuth($authorization) === false) { return; } $params = $this->processParams($handler); if ($params === false) { return; } try { $response = $handler->handle($params); $code = $response->getCode(); } catch (Exception $exception) { $response = new JsonApiResponse(500, ['status' => 'error', 'message' => 'Internal server error']); $code = $response->getCode(); Debugger::log($exception, Debugger::EXCEPTION); } $end = microtime(true); if ($this->context->findByType('Tomaj\\NetteApi\\Logger\\ApiLoggerInterface')) { $this->logRequest($this->context->getByType('Tomaj\\NetteApi\\Logger\\ApiLoggerInterface'), $code, $end - $start); } // output to nette $this->getHttpResponse()->setCode($code); $this->sendResponse($response); }
public function testCreatingResponse() { $jsonResponse = new JsonApiResponse(200, ['asdasd' => 'asdsd']); $this->assertEquals(200, $jsonResponse->getCode()); $this->expectOutputString('{"asdasd":"asdsd"}'); $jsonResponse->send(new Request(new UrlScript()), new Response()); }