public static function YamlSymfony::encode in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony::encode()
Encodes data into the serialization format.
Parameters
mixed $data: The data to encode.
Return value
string The encoded data.
Throws
\Drupal\Component\Serialization\Exception\InvalidDataTypeException
Overrides SerializationInterface::encode
4 calls to YamlSymfony::encode()
- Yaml::encode in core/
lib/ Drupal/ Component/ Serialization/ Yaml.php - Encodes data into the serialization format.
- YamlSymfonyTest::testEncode in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlSymfonyTest.php - Tests our encode settings.
- YamlSymfonyTest::testEncodeDecode in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlSymfonyTest.php - Tests encoding and decoding basic data structures.
- YamlSymfonyTest::testObjectSupportDisabled in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlSymfonyTest.php - Ensures that php object support is disabled.
File
- core/
lib/ Drupal/ Component/ Serialization/ YamlSymfony.php, line 18
Class
- YamlSymfony
- Default serialization for YAML using the Symfony component.
Namespace
Drupal\Component\SerializationCode
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);
}
}