Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b22d1a0

Browse filesBrowse files
author
Amrouche Hamza
committed
[Serializer] add a context key to return csv always as collection
1 parent 424cbcc commit b22d1a0
Copy full SHA for b22d1a0

File tree

2 files changed

+20
-0
lines changed
Filter options

2 files changed

+20
-0
lines changed

‎src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public function decode($data, $format, array $context = array())
150150
}
151151
fclose($handle);
152152

153+
if (isset($context['forceCollection']) && $context['forceCollection']) {
154+
return $result;
155+
}
156+
153157
if (empty($result) || isset($result[1])) {
154158
return $result;
155159
}

‎src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ public function testDecodeCollection()
208208
, 'csv'));
209209
}
210210

211+
public function testDecodeOnlyOneAsCollection()
212+
{
213+
$this->encoder = new CsvEncoder(',', '"', '\\', '.');
214+
215+
$expected = array(
216+
array('foo' => 'a'),
217+
);
218+
219+
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
220+
foo
221+
a
222+
223+
CSV
224+
, 'csv', array('forceCollection' => true)));
225+
}
226+
211227
public function testDecodeToManyRelation()
212228
{
213229
$expected = array(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.