/** * Get all properties from a source object as an associative array * * @param mixed $source * @param bool $firstLevel * @return array */ public static function toArrayFrom($source, $firstLevel = false) { // Prepare the source object type $object = new SerializerObject($source); $object->setStopFirstLevel($firstLevel); return $object->build(); }
/** * @return array */ public function process() { $collection = (array) $this->collection; if (count($collection) === 1) { $collection = $collection[0]; } $object = new SerializerObject($collection); return $object->build(); }
public function testIterator() { $model = new AnyDataset(); $model->AddField("id", 10); $model->AddField("name", 'Testing'); $model->appendRow(); $model->AddField("id", 20); $model->AddField("name", 'Other'); $iterator = $model->getIterator(); $object = new SerializerObject($iterator->toArray()); $result = $object->build(); $this->assertEquals([["id" => 10, "name" => "Testing"], ["id" => 20, "name" => "Other"]], $result); }
public function testFirstLevel_2() { $model = new stdClass(); $model->Obj = [10, 'Joao', new ModelGetter(20, 'JG')]; $object = new SerializerObject($model); $object->setStopFirstLevel(true); $result = $object->build(); $this->assertEquals(["Obj" => [10, 'Joao', new ModelGetter(20, 'JG')]], $result); }