YamlSymfony.php in Drupal 9
File
core/lib/Drupal/Component/Serialization/YamlSymfony.php
View source
<?php
namespace Drupal\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
class YamlSymfony implements SerializationInterface {
public static function encode($data) {
try {
$yaml = new Dumper(2);
return $yaml
->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
} catch (\Exception $e) {
throw new InvalidDataTypeException($e
->getMessage(), $e
->getCode(), $e);
}
}
public static function decode($raw) {
try {
$yaml = new Parser();
return $yaml
->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
} catch (\Exception $e) {
throw new InvalidDataTypeException($e
->getMessage(), $e
->getCode(), $e);
}
}
public static function getFileExtension() {
return 'yml';
}
}
Classes
Name |
Description |
YamlSymfony |
Default serialization for YAML using the Symfony component. |