SerializerInterface.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Messenger\Transport\Serialization;
  11. use Symfony\Component\Messenger\Envelope;
  12. use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
  13. /**
  14. * @author Samuel Roze <samuel.roze@gmail.com>
  15. */
  16. interface SerializerInterface
  17. {
  18. /**
  19. * Decodes an envelope and its message from an encoded-form.
  20. *
  21. * The `$encodedEnvelope` parameter is a key-value array that
  22. * describes the envelope and its content, that will be used by the different transports.
  23. *
  24. * The most common keys are:
  25. * - `body` (string) - the message body
  26. * - `headers` (string<string>) - a key/value pair of headers
  27. *
  28. * @throws MessageDecodingFailedException
  29. */
  30. public function decode(array $encodedEnvelope): Envelope;
  31. /**
  32. * Encodes an envelope content (message & stamps) to a common format understandable by transports.
  33. * The encoded array should only contain scalars and arrays.
  34. *
  35. * Stamps that implement NonSendableStampInterface should
  36. * not be encoded.
  37. *
  38. * The most common keys of the encoded array are:
  39. * - `body` (string) - the message body
  40. * - `headers` (string<string>) - a key/value pair of headers
  41. */
  42. public function encode(Envelope $envelope): array;
  43. }