public static function Yaml::encode

public static Yaml::encode($data)

Encodes data into the serialization format.

Parameters

mixed $data: The data to encode.

Return value

string The encoded data.

Overrides SerializationInterface::encode

File

core/lib/Drupal/Component/Serialization/Yaml.php, line 17

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Serialization!Yaml.php/function/Yaml::encode/8.1.x