class Yaml
Same name in this branch
- 10 core/lib/Drupal/Core/Serialization/Yaml.php \Drupal\Core\Serialization\Yaml
Same name in other branches
- 9 core/lib/Drupal/Core/Serialization/Yaml.php \Drupal\Core\Serialization\Yaml
- 9 core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
- 8.9.x core/lib/Drupal/Core/Serialization/Yaml.php \Drupal\Core\Serialization\Yaml
- 8.9.x core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
- 11.x core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
Provides a YAML serialization implementation using symfony/yaml.
Hierarchy
- class \Drupal\Component\Serialization\Yaml implements \Drupal\Component\Serialization\SerializationInterface
Expanded class hierarchy of Yaml
21 files declare their use of Yaml
- ConfigConfiguratorTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ ConfigConfiguratorTest.php - ConfigValidationTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ ConfigValidationTest.php - ContentImportTest.php in core/
tests/ Drupal/ FunctionalTests/ DefaultContent/ ContentImportTest.php - DependencyTest.php in core/
modules/ system/ tests/ src/ Functional/ Module/ DependencyTest.php - DistributionProfileExistingSettingsTest.php in core/
tests/ Drupal/ FunctionalTests/ Installer/ DistributionProfileExistingSettingsTest.php
2 string references to 'Yaml'
- core.services.yml in core/
core.services.yml - core/core.services.yml
- YamlSymfonyTest::taggedValuesProvider in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlSymfonyTest.php - Data provider for testCustomTagSupport().
1 service uses Yaml
File
-
core/
lib/ Drupal/ Component/ Serialization/ Yaml.php, line 13
Namespace
Drupal\Component\SerializationView source
class Yaml 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 | SymfonyYaml::PARSE_CUSTOM_TAGS);
} catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* {@inheritdoc}
*/
public static function getFileExtension() {
return 'yml';
}
/**
* Determines which implementation to use for parsing YAML.
*
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
* replacement.
*
* @see https://www.drupal.org/node/3415489
*/
protected static function getSerializer() {
@trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED);
return YamlSymfony::class;
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
Yaml::decode | public static | function | Decodes data from the serialization format. | Overrides SerializationInterface::decode | 1 | |
Yaml::encode | public static | function | Encodes data into the serialization format. | Overrides SerializationInterface::encode | ||
Yaml::getFileExtension | public static | function | Gets the file extension for this serialization format. | Overrides SerializationInterface::getFileExtension | ||
Yaml::getSerializer | Deprecated | protected static | function | Determines which implementation to use for parsing YAML. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.