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

Commitb399527

Browse files
committed
feature#28815 YamlEncoder handle yml format (kevin-biig)
This PR was merged into the 4.2-dev branch.Discussion----------YamlEncoder handle yml format| Q | A| ------------- | ---| Branch? | ?| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#28768| License | MIT`Symfony\Component\Serializer\Encoder\YamlEncoder` now handle the `yml` format too```use Symfony\Component\Serializer\Serializer;use Symfony\Component\Serializer\Encoder\YamlEncoder;$serializer = new Serializer([], [new YamlEncoder()]);$content = file_get_contents(__DIR__ . '/test.yml');$data = $serializer->decode($content, YamlEncoder::ALTERNATIVE_FORMAT);```Let me know if something is wrong for youCommits-------d8640f9 YamlEncoder handle yml extension
2 parents4a4fda5 +d8640f9 commitb399527

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

‎src/Symfony/Component/Serializer/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CHANGELOG
2323
* added the optional`$objectClassResolver` argument in`AbstractObjectNormalizer`
2424
and`ObjectNormalizer` constructor
2525
* added`MetadataAwareNameConverter` to configure the serialized name of properties through metadata
26+
*`YamlEncoder` now handle the`.yml` extension too
2627

2728
4.1.0
2829
-----

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class YamlEncoderimplements EncoderInterface, DecoderInterface
2424
{
2525
constFORMAT ='yaml';
26+
constALTERNATIVE_FORMAT ='yml';
2627

2728
private$dumper;
2829
private$parser;
@@ -54,7 +55,7 @@ public function encode($data, $format, array $context = array())
5455
*/
5556
publicfunctionsupportsEncoding($format)
5657
{
57-
returnself::FORMAT ===$format;
58+
returnself::FORMAT ===$format ||self::ALTERNATIVE_FORMAT ===$format;
5859
}
5960

6061
/**
@@ -72,6 +73,6 @@ public function decode($data, $format, array $context = array())
7273
*/
7374
publicfunctionsupportsDecoding($format)
7475
{
75-
returnself::FORMAT ===$format;
76+
returnself::FORMAT ===$format ||self::ALTERNATIVE_FORMAT ===$format;
7677
}
7778
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testSupportsEncoding()
3535
$encoder =newYamlEncoder();
3636

3737
$this->assertTrue($encoder->supportsEncoding('yaml'));
38+
$this->assertTrue($encoder->supportsEncoding('yml'));
3839
$this->assertFalse($encoder->supportsEncoding('json'));
3940
}
4041

@@ -51,6 +52,7 @@ public function testSupportsDecoding()
5152
$encoder =newYamlEncoder();
5253

5354
$this->assertTrue($encoder->supportsDecoding('yaml'));
55+
$this->assertTrue($encoder->supportsDecoding('yml'));
5456
$this->assertFalse($encoder->supportsDecoding('json'));
5557
}
5658

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp