Skip to content

Navigation Menu

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 cbe28c0

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

File tree

2 files changed

+18
-0
lines changed
Filter options

2 files changed

+18
-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
@@ -153,6 +153,10 @@ public function decode($data, $format, array $context = array())
153153
}
154154
fclose($handle);
155155

156+
if (isset($context['alwaysAsCollection']) && true === $context['alwaysAsCollection']) {
157+
return $result;
158+
}
159+
156160
if (empty($result) || isset($result[1])) {
157161
return $result;
158162
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ public function testDecodeCollection()
178178
, 'csv'));
179179
}
180180

181+
public function testDecodeOnlyOneAsCollection()
182+
{
183+
$expected = array(
184+
array('foo' => 'a'),
185+
);
186+
187+
$this->assertEquals($expected, $this->encoder->decode(<<<'CSV'
188+
foo
189+
a
190+
191+
CSV
192+
, 'csv', array('alwaysAsCollection' => true)));
193+
}
194+
181195
public function testDecodeToManyRelation()
182196
{
183197
$expected = array(

0 commit comments

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