Пример #1
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;
 }
Пример #2
0
 /**
  * @covers \PG\JsonRpc\Call
  */
 public function testSanitizeArrays()
 {
     $logger = \Mockery::mock('Monolog\\Logger');
     $logger->shouldReceive('addDebug')->once()->with('Executing method.', array('method' => 'PG\\JsonRpc\\tests\\sample\\Sample.withArray', 'params' => array('Array')));
     $app = new \Pimple();
     $app['logger'] = $logger;
     $call = new Call($this->makeCall('Sample.withArray', array(array(1, 2, 3))), array('Sample' => 'PG\\JsonRpc\\tests\\sample\\Sample'), $app);
     $call->execute();
 }