You are here

public static function Yaml::encode in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml::encode()

Encodes data into the serialization format.

Parameters

mixed $data: The data to encode.

Return value

string The encoded data.

Overrides SerializationInterface::encode

File

lib/Drupal/Component/Serialization/Yaml.php, line 22
Contains \Drupal\Component\Serialization\Yaml.

Class

Yaml
Default serialization for YAML using the Symfony component.

Namespace

Drupal\Component\Serialization

Code

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);
  }
}