Skip to content

Commit

Permalink
Updated serialization component
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateu Aguiló Bosch committed Apr 17, 2015
1 parent ddd3208 commit 94ed3b8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Drupal/Component/Serialization/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace Drupal\Component\Serialization;

use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Symfony\Component\Yaml\Yaml as Symfony;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;

/**
* Default serialization for YAML using the Symfony component.
Expand All @@ -20,7 +21,9 @@ class Yaml implements SerializationInterface {
*/
public static function encode($data) {
try {
return Symfony::dump($data, PHP_INT_MAX, 2, TRUE);
$yaml = new Dumper();
$yaml->setIndentation(2);
return $yaml->dump($data, PHP_INT_MAX, 0, TRUE, FALSE);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
Expand All @@ -32,7 +35,10 @@ public static function encode($data) {
*/
public static function decode($raw) {
try {
return Symfony::parse($raw, TRUE);
$yaml = new Parser();
// Make sure we have a single trailing newline. A very simple config like
// 'foo: bar' with no newline will fail to parse otherwise.
return $yaml->parse($raw, TRUE, FALSE);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
Expand Down

0 comments on commit 94ed3b8

Please sign in to comment.