/** * {@inheritdoc} */ public function execute(Request $request) { $start = microtime(true); $httpRequest = new HTTP\Request(); $body = new Body(); $httpResponse = new HTTP\Response(); $httpResponse->setBody($body); try { $result = $this->runCallback($httpRequest, $httpResponse); $body->append($result); } catch (\Exception $e) { $httpResponse->setResponseCode(500); //TODO: Maybe implement something more complex, with better error reporting? Error::printException($e, false); $body->append(sprintf('Error: %s', $e->getMessage())); } $this->prepareResponse($httpResponse); return $httpResponse->toArray(); }
public function testToArrayWithoutDefaults() { $body = new Body(); $body->append(rand(0, 100000)); $response = new Response(); $response->setBody($body); $array = $response->toArray(false); $this->assertSame(0, $array['responseCode']); $this->assertSame((string) $body, $array['body']); $this->assertFalse(isset($array['headers']['Server'])); $this->assertFalse(isset($array['headers']['Content-Type'])); $this->assertSame((string) strlen($body), $array['headers']['Content-Length']); }