Пример #1
0
 public function __invoke(Request $request, Response $response, callable $next)
 {
     $request->registerMediaTypeParser('application/json', function ($input) {
         return json_decode($input);
     });
     return $next($request, $response);
 }
 /**
  * @expectedException \RuntimeException
  */
 public function testGetParsedBodyAsArray()
 {
     $uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
     $headers = new Headers(['Content-Type' => 'application/json;charset=utf8']);
     $cookies = [];
     $serverParams = [];
     $body = new RequestBody();
     $body->write('{"foo": "bar"}');
     $body->rewind();
     $request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
     $request->registerMediaTypeParser('application/json', function ($input) {
         return 10;
         // <-- Return invalid body value
     });
     $request->getParsedBody();
     // <-- Triggers exception
 }