コード例 #1
0
 /**
  * Serialize instance to json ready array.
  *
  * @param \Illuminate\Support\Contracts\ArrayableInterface $instance
  * @param string $root
  * @return array
  */
 public function serialize(ArrayableInterface $instance, $root)
 {
     $relationship = array();
     $serialized_data = parent::serialize($instance, $root);
     $root = $this->getRoot($instance, $root);
     if ($this->with_relations) {
         $serialized_data[$root] = $this->serializeKeys($instance)->toArray();
     }
     return array_merge($serialized_data, $relationship);
 }
コード例 #2
0
 public function testSerializeNested()
 {
     $obj = new RESTModelStub();
     $fooobj = new RESTModelStub();
     $fooobj->foo = 'bar';
     $collection = new Collection();
     $collection->push($fooobj);
     $obj->setRelation('foos', $collection);
     $serializer = new BaseSerializer();
     $this->assertEquals(array('fred' => array('foos' => array(array('foo' => 'bar')))), $serializer->serialize($obj, 'fred'));
 }