Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Encoder/YamlEncoder.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Serializer\Encoder; | |
13 | |
14 use Symfony\Component\Yaml\Dumper; | |
15 use Symfony\Component\Yaml\Parser; | |
16 | |
17 /** | |
18 * Encodes YAML data. | |
19 * | |
20 * @author Kévin Dunglas <dunglas@gmail.com> | |
21 */ | |
22 class YamlEncoder implements EncoderInterface, DecoderInterface | |
23 { | |
24 const FORMAT = 'yaml'; | |
25 | |
26 private $dumper; | |
27 private $parser; | |
28 private $defaultContext = array('yaml_inline' => 0, 'yaml_indent' => 0, 'yaml_flags' => 0); | |
29 | |
30 public function __construct(Dumper $dumper = null, Parser $parser = null, array $defaultContext = array()) | |
31 { | |
32 $this->dumper = $dumper ?: new Dumper(); | |
33 $this->parser = $parser ?: new Parser(); | |
34 $this->defaultContext = array_merge($this->defaultContext, $defaultContext); | |
35 } | |
36 | |
37 /** | |
38 * {@inheritdoc} | |
39 */ | |
40 public function encode($data, $format, array $context = array()) | |
41 { | |
42 $context = array_merge($this->defaultContext, $context); | |
43 | |
44 return $this->dumper->dump($data, $context['yaml_inline'], $context['yaml_indent'], $context['yaml_flags']); | |
45 } | |
46 | |
47 /** | |
48 * {@inheritdoc} | |
49 */ | |
50 public function supportsEncoding($format) | |
51 { | |
52 return self::FORMAT === $format; | |
53 } | |
54 | |
55 /** | |
56 * {@inheritdoc} | |
57 */ | |
58 public function decode($data, $format, array $context = array()) | |
59 { | |
60 $context = array_merge($this->defaultContext, $context); | |
61 | |
62 return $this->parser->parse($data, $context['yaml_flags']); | |
63 } | |
64 | |
65 /** | |
66 * {@inheritdoc} | |
67 */ | |
68 public function supportsDecoding($format) | |
69 { | |
70 return self::FORMAT === $format; | |
71 } | |
72 } |