Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
CRAP | |
60.00% |
6 / 10 |
| Yaml | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
6.60 | |
60.00% |
6 / 10 |
| encode | |
0.00% |
0 / 1 |
2.26 | |
60.00% |
3 / 5 |
|||
| decode | |
0.00% |
0 / 1 |
2.50 | |
50.00% |
2 / 4 |
|||
| getFileExtension | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Component\Serialization\Yaml. | |
| */ | |
| namespace Drupal\Component\Serialization; | |
| use Drupal\Component\Serialization\Exception\InvalidDataTypeException; | |
| use Symfony\Component\Yaml\Parser; | |
| use Symfony\Component\Yaml\Dumper; | |
| /** | |
| * Default serialization for YAML using the Symfony component. | |
| */ | |
| class Yaml implements SerializationInterface { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function encode($data) { | |
| try { | |
| $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); | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function decode($raw) { | |
| try { | |
| $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); | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function getFileExtension() { | |
| return 'yml'; | |
| } | |
| } |