Example #1
0
 public function testBatch()
 {
     $collection = new Request();
     $this->assertEquals(false, $collection->isBatch());
     $entity = new EntityRequest();
     $collection->append($entity);
     $this->assertEquals(false, $collection->isBatch());
     $entity = new EntityRequest();
     $collection->offsetSet('will_not_be_used', $entity);
     $this->assertEquals(true, $collection->isBatch());
 }
Example #2
0
 /**
  * Prepare the request for sending
  *
  * @param Collection\Request $request
  * @return string A JSON encoded JSON RPC string
  */
 protected function prepareRequest(Collection\Request $request)
 {
     $data = $request->getArrayCopy();
     foreach ($data as $index => $value) {
         if ($value['jsonrpc'] === null) {
             unset($data[$index]['jsonrpc']);
         }
         if (empty($value['params'])) {
             unset($data[$index]['params']);
         }
         if ($value['id'] === null) {
             unset($data[$index]['id']);
         }
     }
     // On single request we do not send in batch mode
     if ($request->isBatch() === false) {
         $data = array_shift($data);
     }
     $json = @json_encode($data);
     if ($json === false) {
         throw new Exception\RuntimeException('Could not encode request data', 1);
     }
     return $json;
 }