Json.php 666 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Drupal\Component\Serialization;
  3. /**
  4. * Default serialization for JSON.
  5. *
  6. * @ingroup third_party
  7. */
  8. class Json implements SerializationInterface {
  9. /**
  10. * {@inheritdoc}
  11. *
  12. * Uses HTML-safe strings, with several characters escaped.
  13. */
  14. public static function encode($variable) {
  15. // Encode <, >, ', &, and ".
  16. return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function decode($string) {
  22. return json_decode($string, TRUE);
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function getFileExtension() {
  28. return 'json';
  29. }
  30. }