Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Yaml.php

class Yaml

Same name in this branch
  1. 11.1.x vendor/symfony/validator/Constraints/Yaml.php \Symfony\Component\Validator\Constraints\Yaml
  2. 11.1.x vendor/symfony/yaml/Yaml.php \Symfony\Component\Yaml\Yaml

Provides a YAML serialization implementation using symfony/yaml.

Hierarchy

  • class \Drupal\Component\Serialization\Yaml implements \Drupal\Component\Serialization\SerializationInterface

Expanded class hierarchy of Yaml

6 files declare their use of Yaml
Finder.php in core/lib/Drupal/Core/DefaultContent/Finder.php
GenerateTheme.php in core/lib/Drupal/Core/Command/GenerateTheme.php
InstalledPackage.php in core/modules/package_manager/src/InstalledPackage.php
Recipe.php in core/lib/Drupal/Core/Recipe/Recipe.php
YamlDirectoryDiscovery.php in core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php

... See full list

4 string references to 'Yaml'
LintCommand::getFiles in vendor/symfony/yaml/Command/LintCommand.php
PlatformRepository::initialize in vendor/composer/composer/src/Composer/Repository/PlatformRepository.php
Initializes the packages array. Mostly meant as an extension point.
YamlFileLoader::supports in vendor/symfony/routing/Loader/YamlFileLoader.php
YamlFileLoader::supports in vendor/symfony/dependency-injection/Loader/YamlFileLoader.php

File

core/lib/Drupal/Component/Serialization/Yaml.php, line 13

Namespace

Drupal\Component\Serialization
View source
class Yaml implements SerializationInterface {
    
    /**
     * {@inheritdoc}
     */
    public static function encode($data) {
        try {
            // Set the indentation to 2 to match Drupal's coding standards.
            $yaml = new Dumper(2);
            return $yaml->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
        } 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, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::PARSE_CUSTOM_TAGS);
        } catch (\Exception $e) {
            throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getFileExtension() {
        return 'yml';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
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
RSS feed
Powered by Drupal