You are here

class Yaml in Plug 7

Same name in this branch
  1. 7 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
  2. 7 lib/Symfony/yaml/Symfony/Component/Yaml/Yaml.php \Symfony\Component\Yaml\Yaml

Default serialization for YAML using the Symfony component.

Hierarchy

Expanded class hierarchy of Yaml

1 file declares its use of Yaml
YamlDiscovery.php in lib/Drupal/Component/Discovery/YamlDiscovery.php
Contains \Drupal\Component\Discovery\YamlDiscovery.

File

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

Namespace

Drupal\Component\Serialization
View source
class Yaml implements SerializationInterface {

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

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

  /**
   * {@inheritdoc}
   */
  public static function getFileExtension() {
    return 'yml';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Yaml::decode public static function Decodes data from the serialization format. Overrides SerializationInterface::decode
Yaml::encode public static function Encodes data into the serialization format. Overrides SerializationInterface::encode
Yaml::getFileExtension public static function Gets the file extension for this serialization format. Overrides SerializationInterface::getFileExtension