コード例 #1
0
ファイル: Process.php プロジェクト: skeetr/skeetr
 /**
  * {@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();
 }
コード例 #2
0
ファイル: ResponseTest.php プロジェクト: skeetr/skeetr
 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']);
 }