3 namespace Drupal\Component\Serialization;
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Symfony\Component\Yaml\Parser;
7 use Symfony\Component\Yaml\Dumper;
10 * Default serialization for YAML using the Symfony component.
12 class YamlSymfony implements SerializationInterface {
17 public static function encode($data) {
20 $yaml->setIndentation(2);
21 return $yaml->dump($data, PHP_INT_MAX, 0, TRUE, FALSE);
23 catch (\Exception $e) {
24 throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
31 public static function decode($raw) {
34 // Make sure we have a single trailing newline. A very simple config like
35 // 'foo: bar' with no newline will fail to parse otherwise.
36 return $yaml->parse($raw, TRUE, FALSE);
38 catch (\Exception $e) {
39 throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
46 public static function getFileExtension() {