You are here

public static function YamlSymfony::decode in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony::decode()
  2. 10 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony::decode()

Decodes data from the serialization format.

Parameters

string $raw: The raw data string to decode.

Return value

mixed The decoded data.

Throws

\Drupal\Component\Serialization\Exception\InvalidDataTypeException

Overrides SerializationInterface::decode

5 calls to YamlSymfony::decode()
YamlSymfonyTest::testDecode in core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
Tests decoding YAML node anchors.
YamlSymfonyTest::testEncodeDecode in core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
Tests encoding and decoding basic data structures.
YamlSymfonyTest::testError in core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
Tests that invalid YAML throws an exception.
YamlTest::testObjectSupportDisabledSymfony in core/tests/Drupal/Tests/Component/Serialization/YamlTest.php
Ensures that decoding php objects does not work in Symfony.
YamlTest::testYamlFiles in core/tests/Drupal/Tests/Component/Serialization/YamlTest.php
Tests all YAML files are decoded in the same way with Symfony and PECL.

File

core/lib/Drupal/Component/Serialization/YamlSymfony.php, line 32

Class

YamlSymfony
Default serialization for YAML using the Symfony component.

Namespace

Drupal\Component\Serialization

Code

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);
  } catch (\Exception $e) {
    throw new InvalidDataTypeException($e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}