Example #1
0
 public function testBatch()
 {
     $collection = new Response();
     $this->assertEquals(false, $collection->isBatch());
     $entity = new EntityResponse();
     $collection->append($entity);
     $this->assertEquals(false, $collection->isBatch());
     $entity = new EntityResponse();
     $collection->append($entity);
     $this->assertEquals(true, $collection->isBatch());
 }
Example #2
0
 /**
  * Create an correct JSON response based on Response object
  *
  * @param  Entity\Response $response
  * @return string
  */
 public function createRawResponseFromResponse(Collection\Response $response)
 {
     // Get the array
     $collection = $response->getArrayCopy();
     foreach ($collection as &$singleResponse) {
         // JSON RPC should be set for returning
         if ($singleResponse['jsonrpc'] === null) {
             unset($singleResponse['jsonrpc']);
         }
         // Check if we should return result or error
         if (empty($singleResponse['error']) === false) {
             unset($singleResponse['result']);
             if (empty($singleResponse['error']['data'])) {
                 unset($singleResponse['error']['data']);
             }
         } else {
             unset($singleResponse['error']);
         }
     }
     // Make it single on a non batch request
     if ($response->isBatch() === false) {
         $collection = array_shift($collection);
     }
     // Encode the remaining array
     return json_encode($collection);
 }