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 b399527

Browse filesBrowse 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 you Commits ------- d8640f9 YamlEncoder handle yml extension
2 parents 4a4fda5 + d8640f9 commit b399527
Copy full SHA for b399527

File tree

Expand file treeCollapse file tree

3 files changed

+6
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CHANGELOG.md
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class YamlEncoder implements EncoderInterface, DecoderInterface
2424
{
2525
const FORMAT = 'yaml';
26+
const ALTERNATIVE_FORMAT = 'yml';
2627

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

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/YamlEncoderTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testSupportsEncoding()
3535
$encoder = new YamlEncoder();
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 = new YamlEncoder();
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.