Beispiel #1
0
 public function handle(IServerRequest $request)
 {
     $doc = MimedDocument::createText('test');
     $uri = Uri::createFromString('/test');
     switch ($request->getQueryParams()['r']) {
         case 'ok':
             return $this->responseOk($doc);
             break;
         case 'bad_request':
             return $this->responseBadRequest($doc);
             break;
         case 'forbidden':
             return $this->responseForbidden($doc);
             break;
         case 'not_found':
             return $this->responseNotFound($doc);
             break;
         case 'redirect_perm':
             return $this->redirect($uri, true);
             break;
         case 'redirect_temp':
             return $this->redirect($uri, false);
             break;
         case 'error':
             return $this->responseError($doc);
             break;
         default:
             throw new \LogicException('Undefined');
             break;
     }
 }
Beispiel #2
0
 public function testCreateJson()
 {
     $doc = MimedDocument::createJson('foo');
     $this->assertInstanceOf(MimedDocument::class, $doc);
     $this->assertEquals('application/json', $doc->mime());
     $this->assertEquals('foo', $doc->content());
     $this->assertEquals('foo', $doc);
 }
Beispiel #3
0
 protected function createDocument($content)
 {
     return MimedDocument::createText($content);
 }
Beispiel #4
0
 public function render($data)
 {
     return MimedDocument::createText(print_r($data, true));
 }
Beispiel #5
0
 public function render($data)
 {
     return MimedDocument::createJson(json_encode($data));
 }