function YamlPecl::encode

Same name in other branches
  1. 9 core/lib/Drupal/Component/Serialization/YamlPecl.php \Drupal\Component\Serialization\YamlPecl::encode()
  2. 8.9.x core/lib/Drupal/Component/Serialization/YamlPecl.php \Drupal\Component\Serialization\YamlPecl::encode()
  3. 11.x core/lib/Drupal/Component/Serialization/YamlPecl.php \Drupal\Component\Serialization\YamlPecl::encode()

Overrides SerializationInterface::encode

3 calls to YamlPecl::encode()
YamlPeclTest::testEncode in core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
Tests our encode settings.
YamlPeclTest::testEncodeDecode in core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
Tests encoding and decoding basic data structures.
YamlPeclTest::testObjectSupportDisabled in core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
Ensures that php object support is disabled.

File

core/lib/Drupal/Component/Serialization/YamlPecl.php, line 15

Class

YamlPecl
Provides default serialization for YAML using the PECL extension.

Namespace

Drupal\Component\Serialization

Code

public static function encode($data) {
    static $init;
    if (!isset($init)) {
        ini_set('yaml.output_indent', 2);
        // Do not break lines at 80 characters.
        ini_set('yaml.output_width', -1);
        $init = TRUE;
    }
    return yaml_emit($data, YAML_UTF8_ENCODING, YAML_LN_BREAK);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.