public function send($code = 200, array $headers = null, $body = null) { $this->response->setCode($code); if (null !== $body) { $this->response->setBody($body); } else { if (null !== $this->view) { $this->response->setBody($this->view->render()); } } $this->response->send($code, $headers); }
/** * Send response * * @param int $code * @param array $headers * @param string $body * @return void */ public function send($code = 200, array $headers = null, $body = null) { $this->response->setCode($code); $this->application->trigger('app.send.pre', ['controller' => $this]); if (null !== $body) { $this->response->setBody($body); } else { if (null !== $this->view) { $this->response->setBody($this->view->render()); } } $this->application->trigger('app.send.post', ['controller' => $this]); $this->response->send($code, $headers); }
/** * Method to send a JSON response * * @param mixed $values * @param int $code * @param array $headers * @return void */ public function sendJson($values, $code = 200, array $headers = null) { // Build the response and send it $response = new Response(); $this->response->setCode($code); if (null !== $headers) { foreach ($headers as $name => $value) { $this->response->setHeader($name, $value); } } // Force JSON content-type header $response->setHeader('Content-Type', 'application/json')->setBody(json_encode($values)); $response->send(); }
public function testSetCodeException() { $this->setExpectedException('Pop\\Http\\Exception'); $r = new Response(200, array('Content-Type' => 'text/plain')); $r->setCode(601); }