Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony
  2. 9 core/lib/Drupal/Component/Serialization/YamlSymfony.php \Drupal\Component\Serialization\YamlSymfony

Default serialization for YAML using the Symfony component.

Hierarchy

Expanded class hierarchy of YamlSymfony

Deprecated

in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml instead.

See also

https://www.drupal.org/node/3415489

File

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

Namespace

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

  /**
   * {@inheritdoc}
   */
  public static function encode($data) {
    @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \\Drupal\\Component\\Serialization\\Yaml::encode() instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED);
    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) {
    @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \\Drupal\\Component\\Serialization\\Yaml::decode() instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED);
    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() {
    @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \\Drupal\\Component\\Serialization\\Yaml::getFileExtension() instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED);
    return 'yml';
  }

}

Members

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