class Yaml in Service Container 7.2
Same name in this branch
- 7.2 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
- 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Yaml.php \Symfony\Component\Yaml\Yaml
Same name and namespace in other branches
- 7 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
Default serialization for YAML using the Symfony component.
Hierarchy
- class \Drupal\Component\Serialization\Yaml implements SerializationInterface
Expanded class hierarchy of Yaml
2 files declare their use of Yaml
- YamlDiscovery.php in lib/
Drupal/ Component/ Discovery/ YamlDiscovery.php - Contains \Drupal\Component\Discovery\YamlDiscovery.
- YamlFileLoader.php in lib/
Drupal/ Core/ DependencyInjection/ YamlFileLoader.php - Contains \Drupal\Core\DependencyInjection\YamlFileLoader.
File
- lib/
Drupal/ Component/ Serialization/ Yaml.php, line 17 - Contains \Drupal\Component\Serialization\Yaml.
Namespace
Drupal\Component\SerializationView source
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';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Yaml:: |
public static | function |
Decodes data from the serialization format. Overrides SerializationInterface:: |
|
Yaml:: |
public static | function |
Encodes data into the serialization format. Overrides SerializationInterface:: |
|
Yaml:: |
public static | function |
Gets the file extension for this serialization format. Overrides SerializationInterface:: |