diff --git a/lib/Drupal/Component/Serialization/Exception/InvalidDataTypeException.php b/lib/Drupal/Component/Serialization/Exception/InvalidDataTypeException.php new file mode 100644 index 0000000..e4f9211 --- /dev/null +++ b/lib/Drupal/Component/Serialization/Exception/InvalidDataTypeException.php @@ -0,0 +1,14 @@ +, ', &, and ". + return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT); + } + + /** + * {@inheritdoc} + */ + public static function decode($string) { + return json_decode($string, TRUE); + } + + /** + * {@inheritdoc} + */ + public static function getFileExtension() { + return 'json'; + } + +} diff --git a/lib/Drupal/Component/Serialization/PhpSerialize.php b/lib/Drupal/Component/Serialization/PhpSerialize.php new file mode 100644 index 0000000..a6f11fc --- /dev/null +++ b/lib/Drupal/Component/Serialization/PhpSerialize.php @@ -0,0 +1,36 @@ +getMessage(), $e->getCode(), $e); + } + } + + /** + * {@inheritdoc} + */ + public static function decode($raw) { + try { + return Symfony::parse($raw, TRUE); + } + catch (\Exception $e) { + throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); + } + } + + /** + * {@inheritdoc} + */ + public static function getFileExtension() { + return 'yml'; + } + +}