Mercurial > hg > isophonics-drupal-site
view core/lib/Drupal/Component/Serialization/YamlSymfony.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
line wrap: on
line source
<?php namespace Drupal\Component\Serialization; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Yaml as SymfonyYaml; /** * Default serialization for YAML using the Symfony component. */ class YamlSymfony 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); } 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); } catch (\Exception $e) { throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); } } /** * {@inheritdoc} */ public static function getFileExtension() { return 'yml'; } }