Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bfb101

Browse files
author
Kevin Grenier
committed
YamlEncoder handle yml format
1 parent f0168e3 commit 0bfb101

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* `AbstractNormalizer::handleCircularReference` is now final, and receives two optional extra arguments: the format and the context
8+
* `YamlEncoder` now handle the `yml` format too
89

910
4.1.0
1011
-----

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
use Symfony\Component\Yaml\Parser;
1717

1818
/**
19-
* Encodes YAML data.
19+
* Encodes YAML/YML data.
2020
*
2121
* @author Kévin Dunglas <[email protected]>
2222
*/
2323
class YamlEncoder implements EncoderInterface, DecoderInterface
2424
{
25-
const FORMAT = 'yaml';
25+
const FORMAT = self::YAML_FORMAT;
26+
const YAML_FORMAT = 'yaml';
27+
const YML_FORMAT = 'yml';
28+
const VALID_FORMAT = [self::YAML_FORMAT, self::YML_FORMAT];
2629

2730
private $dumper;
2831
private $parser;
@@ -54,7 +57,7 @@ public function encode($data, $format, array $context = array())
5457
*/
5558
public function supportsEncoding($format)
5659
{
57-
return self::FORMAT === $format;
60+
return \in_array($format, self::VALID_FORMAT, true);
5861
}
5962

6063
/**
@@ -72,6 +75,6 @@ public function decode($data, $format, array $context = array())
7275
*/
7376
public function supportsDecoding($format)
7477
{
75-
return self::FORMAT === $format;
78+
return \in_array($format, self::VALID_FORMAT, true);
7679
}
7780
}

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 = 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)