You are here

class Yaml in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/yaml/Yaml.php \Symfony\Component\Yaml\Yaml
  2. 8 core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/Serialization/Yaml.php \Drupal\Component\Serialization\Yaml

Default serialization for YAML using the Symfony component.

Hierarchy

Expanded class hierarchy of Yaml

20 files declare their use of Yaml
ConfigController.php in core/modules/config/src/Controller/ConfigController.php
Contains \Drupal\config\Controller\ConfigController.
ConfigExportUITest.php in core/modules/config/src/Tests/ConfigExportUITest.php
Contains \Drupal\config\Tests\ConfigExportUITest.
ConfigInstallProfileUnmetDependenciesTest.php in core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
Contains \Drupal\config\Tests\ConfigInstallProfileUnmetDependenciesTest.
ConfigManager.php in core/lib/Drupal/Core/Config/ConfigManager.php
Contains \Drupal\Core\Config\ConfigManager.
ConfigSingleExportForm.php in core/modules/config/src/Form/ConfigSingleExportForm.php
Contains \Drupal\config\Form\ConfigSingleExportForm.

... See full list

1 string reference to 'Yaml'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses Yaml
serialization.yaml in core/core.services.yml
Drupal\Component\Serialization\Yaml

File

core/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