Пример #1
0
 public function testEncode()
 {
     $obj = array('name' => 'putra', 'age' => 17);
     $json = \JsonKit\JsonKit::encode($obj);
     $a = json_decode($json);
     $this->assertEquals((array) $obj, (array) $a, 'Source object should be equals to the json_decoded json string result');
 }
Пример #2
0
 /**
  * [display description]
  *
  * @return [type] [description]
  */
 public function display($template)
 {
     $app = App::getInstance();
     $data = $this->data->all();
     unset($data['flash']);
     unset($data['app']);
     foreach (array_keys($data) as $key) {
         if ($key[0] === '_') {
             unset($data[$key]);
         }
     }
     $app->response->headers['content-type'] = $this->contentType;
     echo \JsonKit\JsonKit::encode($data);
 }
Пример #3
0
 /**
  * Implement the json serializer normalizing the data structures.
  *
  * @return array
  */
 public function jsonSerialize()
 {
     if (!Norm::options('include')) {
         return $this->toArray();
     }
     $destination = array();
     $source = $this->toArray();
     $schema = $this->collection->schema();
     foreach ($source as $key => $value) {
         if (isset($schema[$key]) and isset($value)) {
             $destination[$key] = $schema[$key]->toJSON($value);
         } else {
             $destination[$key] = $value;
         }
         $destination[$key] = JsonKit::replaceObject($destination[$key]);
     }
     return $destination;
 }