Introduce MessageEncoderInterface#308
Conversation
vjik
commented
Jun 11, 2026
| Q | A |
|---|---|
| Is bugfix? | ❌ |
| New feature? | ❌ |
| Breaks BC? | ✔️ |
| Tests pass? | ✔️ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
========================================
Coverage 0.00% 0.00%
- Complexity 330 336 +6
========================================
Files 49 50 +1
Lines 909 920 +11
========================================
- Misses 909 920 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors message serialization by introducing a dedicated wire-format abstraction (MessageEncoderInterface) and replacing the previous JsonMessageSerializer / MessageSerializerInterface with a new MessageSerializer that delegates encoding/decoding to an encoder (default: JSON).
Changes:
- Added
MessageEncoderInterface+MessageEncoderExceptionand implementedJsonMessageEncoder. - Added
MessageSerializerto preserve/restore original message class via metadata while delegating wire encoding to the encoder. - Updated tests, benchmarks, DI config, and docs to the new serializer/encoder structure; removed legacy serializer types.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Message/Serializer/MessageEncoderInterface.php |
New abstraction for encoding/decoding message parts to/from strings. |
src/Message/Serializer/MessageEncoderException.php |
New exception type for encoder failures. |
src/Message/Serializer/JsonMessageEncoder.php |
JSON implementation of the new encoder interface. |
src/Message/Serializer/MessageSerializer.php |
New serializer that uses an encoder and restores original message class from metadata. |
src/Message/MessageSerializerInterface.php |
Removed legacy serializer interface (BC break). |
src/Message/JsonMessageSerializer.php |
Removed legacy JSON serializer (replaced by MessageSerializer + JsonMessageEncoder). |
config/di.php |
DI now binds MessageEncoderInterface to JsonMessageEncoder. |
docs/guide/en/messages-and-handlers.md |
Docs updated to reference JsonMessageEncoder / MessageEncoderInterface. |
docs/guide/en/consuming-messages-from-external-systems.md |
Docs updated to explain MessageSerializer + encoder responsibilities and JSON payload format. |
docs/guide/en/best-practices.md |
Docs updated to reference JsonMessageEncoder as the default JSON mechanism. |
tests/Unit/Message/Serializer/MessageSerializerTest.php |
New unit tests for MessageSerializer behavior (class restoration, envelopes, metadata). |
tests/Unit/Message/Serializer/JsonMessageSerializerTest.php |
New unit tests for JSON decode validation (currently misnamed vs encoder). |
tests/Unit/Message/JsonMessageSerializerTest.php |
Removed legacy serializer tests (replaced by new unit tests). |
tests/Benchmark/Support/VoidAdapter.php |
Benchmark adapter updated to use the new MessageSerializer. |
tests/Benchmark/QueueBench.php |
Benchmark updated for new serializer/encoder usage (currently contains a method call bug). |
Comments suppressed due to low confidence (1)
tests/Benchmark/QueueBench.php:93
MessageSerializerdoesn't have anencode()method (it exposesserialize()/unserialize()). These benchmark params will trigger a fatal error when the benchmark is executed.
yield 'simple mapping' => ['message' => $this->serializer->serialize(new GenericMessage('foo', 'bar'))];
yield 'with envelopes mapping' => [
'message' => $this->serializer->serialize(
new FailureEnvelope(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| } | ||
|
|
||
| return $this->encoder->encode([ | ||
| 'type' => $message->getType(), |
There was a problem hiding this comment.
Type should be enough to get the message class from the mapping.
There was a problem hiding this comment.
We can use one class with different types. For example:
$message1 = new GenericMessage(type: 'send-email', ...);
$message2 = new GenericMessage(type: 'process-order', ...);There was a problem hiding this comment.
That is OK. Message payload will contain send-email, process-order and both will resolve to the same class via mapping (or to GenericMessage if either type is not there or there's no mapping for it).
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>