NormalizerInterface.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\CircularReferenceException;
  12. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  13. use Symfony\Component\Serializer\Exception\InvalidArgumentException;
  14. use Symfony\Component\Serializer\Exception\LogicException;
  15. /**
  16. * @author Jordi Boggiano <j.boggiano@seld.be>
  17. */
  18. interface NormalizerInterface
  19. {
  20. /**
  21. * Normalizes an object into a set of arrays/scalars.
  22. *
  23. * @param mixed $object Object to normalize
  24. * @param string $format Format the normalization result will be encoded as
  25. * @param array $context Context options for the normalizer
  26. *
  27. * @return array|string|int|float|bool|\ArrayObject|null \ArrayObject is used to make sure an empty object is encoded as an object not an array
  28. *
  29. * @throws InvalidArgumentException Occurs when the object given is not a supported type for the normalizer
  30. * @throws CircularReferenceException Occurs when the normalizer detects a circular reference when no circular
  31. * reference handler can fix it
  32. * @throws LogicException Occurs when the normalizer is not called in an expected context
  33. * @throws ExceptionInterface Occurs for all the other cases of errors
  34. */
  35. public function normalize($object, string $format = null, array $context = []);
  36. /**
  37. * Checks whether the given class is supported for normalization by this normalizer.
  38. *
  39. * @param mixed $data Data to normalize
  40. * @param string $format The format being (de-)serialized from or into
  41. *
  42. * @return bool
  43. */
  44. public function supportsNormalization($data, string $format = null);
  45. }