Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0b5588a

Browse files
author
Amrouche Hamza
committed
[Serializer] add a context key to return csv always as collection
1 parent424cbcc commit0b5588a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
2626
constENCLOSURE_KEY ='csv_enclosure';
2727
constESCAPE_CHAR_KEY ='csv_escape_char';
2828
constKEY_SEPARATOR_KEY ='csv_key_separator';
29+
constALWAYS_COLLECTION ='csv_always_collection';
2930
constHEADERS_KEY ='csv_headers';
3031

3132
private$delimiter;
@@ -150,6 +151,10 @@ public function decode($data, $format, array $context = array())
150151
}
151152
fclose($handle);
152153

154+
if ($context[self::ALWAYS_COLLECTION] ??false) {
155+
return$result;
156+
}
157+
153158
if (empty($result) ||isset($result[1])) {
154159
return$result;
155160
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ public function testDecodeCollection()
208208
,'csv'));
209209
}
210210

211+
publicfunctiontestDecodeOnlyOneAsCollection()
212+
{
213+
$expected =array(
214+
array('foo' =>'a'),
215+
);
216+
217+
$this->assertEquals($expected,$this->encoder->decode(<<<'CSV'
218+
foo
219+
a
220+
221+
CSV
222+
,'csv',array(CsvEncoder::ALWAYS_COLLECTION =>true)));
223+
}
224+
211225
publicfunctiontestDecodeToManyRelation()
212226
{
213227
$expected =array(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp