Skip to content
This repository was archived by the owner on Jul 4, 2020. It is now read-only.

Commit f23030f

Browse files
committed
Add multidimensional csv support
1 parent cff9880 commit f23030f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/SoapBox/Formatter/ArrayHelpers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public static function dot(array $data) {
1616
return Arr::dot($data);
1717
}
1818

19+
public static function set(array &$data, $key, $value) {
20+
Arr::set($data, $key, $value);
21+
}
22+
1923
}

src/SoapBox/Formatter/Parsers/CsvParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use InvalidArgumentException;
44
use League\Csv\Reader;
5+
use SoapBox\Formatter\ArrayHelpers;
56

67
class CsvParser extends Parser {
78

@@ -28,7 +29,11 @@ public function toArray() {
2829
for ($j = 0; $j < count($headings); ++$j) {
2930
$row[$headings[$j]] = $temp[$i][$j];
3031
}
31-
$result[] = $row;
32+
$expanded = [];
33+
foreach ($row as $key => $value) {
34+
ArrayHelpers::set($expanded, $key, $value);
35+
}
36+
$result[] = $expanded;
3237
}
3338

3439
return $result;

tests/unit/Parsers/ArrayParserTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,4 @@ public function testtoJsonReturnsJsonRepresentationOfNamedArray() {
5050
$this->assertEquals($expected, $parser->toJson());
5151
}
5252

53-
public function testFunTimes() {
54-
$parser = new ArrayParser([[0,1,2], [2,3,4]]);
55-
var_dump($parser->toCsv());
56-
}
5753
}

tests/unit/Parsers/CsvParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public function testtoJsonReturnsJsonRepresentationOfNamedArray() {
3232
$parser = new CsvParser($this->simpleCsv);
3333
$this->assertEquals($expected, $parser->toJson());
3434
}
35+
3536
}

0 commit comments

Comments
 (0)