DenormalizerInterface.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Normalizer;
  11. use Symfony\Component\Serializer\Exception\BadMethodCallException;
  12. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  13. use Symfony\Component\Serializer\Exception\ExtraAttributesException;
  14. use Symfony\Component\Serializer\Exception\InvalidArgumentException;
  15. use Symfony\Component\Serializer\Exception\LogicException;
  16. use Symfony\Component\Serializer\Exception\RuntimeException;
  17. use Symfony\Component\Serializer\Exception\UnexpectedValueException;
  18. /**
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  20. */
  21. interface DenormalizerInterface
  22. {
  23. /**
  24. * Denormalizes data back into an object of the given class.
  25. *
  26. * @param mixed $data Data to restore
  27. * @param string $type The expected class to instantiate
  28. * @param string $format Format the given data was extracted from
  29. * @param array $context Options available to the denormalizer
  30. *
  31. * @return mixed
  32. *
  33. * @throws BadMethodCallException Occurs when the normalizer is not called in an expected context
  34. * @throws InvalidArgumentException Occurs when the arguments are not coherent or not supported
  35. * @throws UnexpectedValueException Occurs when the item cannot be hydrated with the given data
  36. * @throws ExtraAttributesException Occurs when the item doesn't have attribute to receive given data
  37. * @throws LogicException Occurs when the normalizer is not supposed to denormalize
  38. * @throws RuntimeException Occurs if the class cannot be instantiated
  39. * @throws ExceptionInterface Occurs for all the other cases of errors
  40. */
  41. public function denormalize($data, string $type, string $format = null, array $context = []);
  42. /**
  43. * Checks whether the given class is supported for denormalization by this normalizer.
  44. *
  45. * @param mixed $data Data to denormalize from
  46. * @param string $type The class to which the data should be denormalized
  47. * @param string $format The format being deserialized from
  48. *
  49. * @return bool
  50. */
  51. public function supportsDenormalization($data, string $type, string $format = null);
  52. }