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

Skip to content

Commit 2ecebea

Browse files
committed
[FrameworkBundle] Register the YAML encoder in FrameworkBundle
1 parent 424002b commit 2ecebea

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2727
use Symfony\Component\Config\FileLocator;
2828
use Symfony\Component\PropertyAccess\PropertyAccessor;
29+
use Symfony\Component\Serializer\Encoder\YamlEncoder;
2930
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
3031
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
3132
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
@@ -977,6 +978,12 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
977978
$definition->addTag('serializer.normalizer', array('priority' => -900));
978979
}
979980

981+
if (class_exists(YamlEncoder::class)) {
982+
$definition = $container->register('serializer.encoder.yaml', YamlEncoder::class);
983+
$definition->setPublic(false);
984+
$definition->addTag('serializer.encoder');
985+
}
986+
980987
$loader->load('serializer.xml');
981988
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
982989

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
2626

2727
private $dumper;
2828
private $parser;
29-
private $defaultContext;
29+
private $defaultContext = array('yaml_inline' => 0, 'yaml_indent' => 0, 'yaml_flags' => 0);
3030

31-
public function __construct(Dumper $dumper = null, Parser $parser = null, $defaultContext = array('yaml_inline' => 0, 'yaml_indent' => 0, 'yaml_flags' => 0))
31+
public function __construct(Dumper $dumper = null, Parser $parser = null, $defaultContext = array())
3232
{
3333
$this->dumper = $dumper ?: new Dumper();
3434
$this->parser = $parser ?: new Parser();
35-
$this->defaultContext = $defaultContext;
35+
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
3636
}
3737

3838
/**

0 commit comments

Comments
 (0)