예제 #1
0
 function to_json($data)
 {
     return Converter::toJson($data);
 }
예제 #2
0
 /**
  * Format the response into the right content type.
  *
  * @param string $type
  * @return string
  */
 protected function _format($type)
 {
     $response = array('success' => $this->_success, 'data' => $this->_data);
     if ($this->_code) {
         $response['code'] = $this->_code;
     }
     switch (strtolower($type)) {
         case 'json':
             $format = Converter::toJson($response);
             break;
         case 'xml':
             $format = Converter::toXml($response);
             break;
         case 'html':
         case 'text':
         default:
             $format = (string) $this->_data;
             break;
     }
     return $format;
 }
예제 #3
0
 /**
  * Test that toJson() converts any resource type to a JSON string.
  */
 public function testToJson()
 {
     $this->assertEquals($this->json, Converter::toJson($this->array));
     $this->assertEquals($this->json, Converter::toJson($this->object));
     $this->assertEquals($this->json, Converter::toJson($this->json));
     $this->assertEquals($this->json, Converter::toJson($this->serialized));
     $this->assertEquals($this->json, Converter::toJson($this->xml));
     $test = new TypeContract($this->array);
     $this->assertEquals($this->json, Converter::toJson($test));
     $test = new TypeContract(array('a' => 1));
     $this->assertEquals('{"a":1}', Converter::toJson($test));
 }