You are here

class Yaml in Service Container 7.2

Same name in this branch
  1. 7.2 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
  2. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Yaml.php \Symfony\Component\Yaml\Yaml
Same name and namespace in other branches
  1. 7 lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml

Default serialization for YAML using the Symfony component.

Hierarchy

Expanded class hierarchy of Yaml

2 files declare their use of Yaml
YamlDiscovery.php in lib/Drupal/Component/Discovery/YamlDiscovery.php
Contains \Drupal\Component\Discovery\YamlDiscovery.
YamlFileLoader.php in lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
Contains \Drupal\Core\DependencyInjection\YamlFileLoader.

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