class YamlSymfony in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony
- 10 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony
Default serialization for YAML using the Symfony component.
Hierarchy
- class \Drupal\Component\Serialization\YamlSymfony implements SerializationInterface
Expanded class hierarchy of YamlSymfony
2 files declare their use of YamlSymfony
- YamlSymfonyTest.php in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlSymfonyTest.php - YamlTest.php in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlTest.php
File
- core/
lib/ Drupal/ Component/ Serialization/ YamlSymfony.php, line 13
Namespace
Drupal\Component\SerializationView source
class YamlSymfony implements SerializationInterface {
/**
* {@inheritdoc}
*/
public static function encode($data) {
try {
// Set the indentation to 2 to match Drupal's coding standards.
$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);
}
}
/**
* {@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, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
} catch (\Exception $e) {
throw new InvalidDataTypeException($e
->getMessage(), $e
->getCode(), $e);
}
}
/**
* {@inheritdoc}
*/
public static function getFileExtension() {
return 'yml';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
YamlSymfony:: |
public static | function |
Decodes data from the serialization format. Overrides SerializationInterface:: |
|
YamlSymfony:: |
public static | function |
Encodes data into the serialization format. Overrides SerializationInterface:: |
|
YamlSymfony:: |
public static | function |
Gets the file extension for this serialization format. Overrides SerializationInterface:: |