public function testExport() { $data = [1, 2, ['a' => 'b', 'c' => [7, 8, 9]], 4]; $map = CollectionUtils::fromArray($data); $this->assertSame($data, $map->toArray()); $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => 'e']; $list = CollectionUtils::fromArray($data); $this->assertSame($data, $list->toArray()); }
public function testComplex() { $data = [['a' => 'b'], ['c' => 'd']]; $list = CollectionUtils::fromArray($data); $this->assertTrue($list instanceof ArrayList); $this->assertTrue($list->get(1) instanceof Map); $data = ['a' => [1, 2, 3], 'c' => 'd']; $map = CollectionUtils::fromArray($data); $this->assertTrue($map instanceof Map); $this->assertTrue($map->get('a') instanceof ArrayList); $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => 'e']; $map = CollectionUtils::fromArray($data); $this->assertTrue($map->get('c')->get(1) instanceof Map); }
/** * Returns a collection (list or map) of the provided json * * @param string $json * @return ArrayList */ public static function toCollection($json) { return CollectionUtils::fromArray(json_decode($json, true)); }