SerializerInterface.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Symfony\Component\Serializer;
  3. use Symfony\Component\Serializer\Encoder\EncoderInterface;
  4. /*
  5. * This file is part of the Symfony framework.
  6. *
  7. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. /**
  13. * Defines the interface of the Serializer
  14. *
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. */
  17. interface SerializerInterface
  18. {
  19. /**
  20. * Serializes data in the appropriate format
  21. *
  22. * @param mixed $data any data
  23. * @param string $format format name
  24. * @return string
  25. */
  26. function serialize($data, $format);
  27. /**
  28. * Normalizes any data into a set of arrays/scalars
  29. *
  30. * @param mixed $data data to normalize
  31. * @param string $format format name, present to give the option to normalizers to act differently based on formats
  32. * @return array|scalar
  33. */
  34. function normalize($data, $format);
  35. /**
  36. * Normalizes an object into a set of arrays/scalars
  37. *
  38. * @param object $object object to normalize
  39. * @param string $format format name, present to give the option to normalizers to act differently based on formats
  40. * @param array $properties a list of properties to extract, if null all properties are returned
  41. * @return array|scalar
  42. */
  43. function normalizeObject($object, $format, $properties = null);
  44. /**
  45. * Denormalizes data back into an object of the given class
  46. *
  47. * @param mixed $data data to restore
  48. * @param string $class the expected class to instantiate
  49. * @param string $format format name, present to give the option to normalizers to act differently based on formats
  50. * @return object
  51. */
  52. function denormalizeObject($data, $class, $format = null);
  53. /**
  54. * Encodes data into the given format
  55. *
  56. * @param mixed $data data to encode
  57. * @param string $format format name
  58. * @return array|scalar
  59. */
  60. function encode($data, $format);
  61. /**
  62. * Decodes a string from the given format back into PHP data
  63. *
  64. * @param string $data data to decode
  65. * @param string $format format name
  66. * @return mixed
  67. */
  68. function decode($data, $format);
  69. /**
  70. * @param string $format format name
  71. * @param EncoderInterface $encoder
  72. */
  73. function setEncoder($format, EncoderInterface $encoder);
  74. /**
  75. * @param string $format format name
  76. * @return EncoderInterface
  77. */
  78. function getEncoders();
  79. /**
  80. * @return array[]EncoderInterface
  81. */
  82. function getEncoder($format);
  83. /**
  84. * Checks whether the serializer has an encoder registered for the given format
  85. *
  86. * @param string $format format name
  87. * @return Boolean
  88. */
  89. function hasEncoder($format);
  90. /**
  91. * @param string $format format name
  92. */
  93. function removeEncoder($format);
  94. }