Beispiel #1
0
 public function testBatchRequest()
 {
     $server = $this->assembleServer();
     $server->router()->bindController('foo', ServerTest_FooController::class)->group(ServerTest_Middleware_DenyByContext::class, function (Server\Router $router) {
         $router->bind('bar', ServerTest_BarController::class);
     });
     $server->onException(AccessDeniedHttpException::class, function (\Exception $e, Server\Request $request) {
         return Server\RequestResponse::constructErrorResponse($request->getId(), $e->getMessage(), 403);
     });
     $server->setPayload(json_encode([['jsonrpc' => '2.0', 'method' => 'foo', 'id' => 1], ['jsonrpc' => '2.0', 'method' => 'foo.foo', 'id' => 2], ['jsonrpc' => '2.0', 'method' => 'bar', 'id' => 3]]));
     $context = new stdClass();
     $context->deny = true;
     $response = $server->run($context);
     $expectedResponseData = [(object) ['jsonrpc' => '2.0', 'result' => (object) ['foo_index' => true], 'id' => 1], (object) ['jsonrpc' => '2.0', 'result' => (object) ['foo_foo' => true], 'id' => 2], (object) ['jsonrpc' => '2.0', 'error' => (object) ['message' => 'Access Denied By Context', 'code' => 403], 'id' => 3]];
     $this->assertEquals($expectedResponseData, json_decode($response->getContent()));
 }
Beispiel #2
0
 /**
  * @param \Exception $e
  * @param RequestInterface|null $request
  * @return null|RequestResponse
  */
 private function handleException(\Exception $e, RequestInterface $request = null)
 {
     $handlerResult = $this->runExceptionHandlers($e, $request);
     if (!$handlerResult) {
         $this->logger->error($e);
     }
     if ($request && !$request->getId()) {
         return null;
     }
     if ($handlerResult instanceof RequestResponse) {
         return $handlerResult;
     }
     return RequestResponse::constructExceptionErrorResponse($request ? $request->getId() : null, new InternalErrorException());
 }