/**
  * @covers \PG\JsonRpc\Response::setResult
  */
 public function testSetResult()
 {
     $response = new Response();
     $result = new Result(1, 'result');
     $response->setResult($result);
     $content = JSON::decode($response->getContent());
     $this->assertEquals('result', $content['result']);
 }
Exemple #2
0
 /**
  * Handles a given Request object and returns
  * a Response object which can then be sent to the
  * client.
  *
  * @param Request $request
  * @return Response
  */
 public function handle(Request $request)
 {
     $calls = $request->extract();
     $response = new Response();
     $results = array();
     foreach ($calls as $c) {
         try {
             $call = new Call($c, $this->exposed, $this);
             $results[] = $call->execute();
         } catch (AbstractException $e) {
             if (isset($c['id'])) {
                 $e->setId($c['id']);
             }
             $results[] = $e;
         }
     }
     if (!$request->isBatch()) {
         $response->setResult($results[0]);
     } else {
         $response->setResult(new BatchResult($this, $results));
     }
     return $response;
 }