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
-------
d8640f965b
YamlEncoder handle yml extension
This commit is contained in:
commit
b399527ba1
@ -23,6 +23,7 @@ CHANGELOG
|
||||
* added the optional `$objectClassResolver` argument in `AbstractObjectNormalizer`
|
||||
and `ObjectNormalizer` constructor
|
||||
* added `MetadataAwareNameConverter` to configure the serialized name of properties through metadata
|
||||
* `YamlEncoder` now handle the `.yml` extension too
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
@ -23,6 +23,7 @@ use Symfony\Component\Yaml\Parser;
|
||||
class YamlEncoder implements EncoderInterface, DecoderInterface
|
||||
{
|
||||
const FORMAT = 'yaml';
|
||||
const ALTERNATIVE_FORMAT = 'yml';
|
||||
|
||||
private $dumper;
|
||||
private $parser;
|
||||
@ -54,7 +55,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
||||
*/
|
||||
public function supportsEncoding($format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,6 +73,6 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
||||
*/
|
||||
public function supportsDecoding($format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class YamlEncoderTest extends TestCase
|
||||
$encoder = new YamlEncoder();
|
||||
|
||||
$this->assertTrue($encoder->supportsEncoding('yaml'));
|
||||
$this->assertTrue($encoder->supportsEncoding('yml'));
|
||||
$this->assertFalse($encoder->supportsEncoding('json'));
|
||||
}
|
||||
|
||||
@ -51,6 +52,7 @@ class YamlEncoderTest extends TestCase
|
||||
$encoder = new YamlEncoder();
|
||||
|
||||
$this->assertTrue($encoder->supportsDecoding('yaml'));
|
||||
$this->assertTrue($encoder->supportsDecoding('yml'));
|
||||
$this->assertFalse($encoder->supportsDecoding('json'));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user