simple-bus/serialization
Generic PHP interfaces and classes for serializing SimpleBus message objects, supporting consistent message encoding/decoding for transport and storage. Part of the SimpleBus ecosystem; documentation and issues are maintained in the main SimpleBus repository.
json_encode()/json_decode() may suffice for simple cases.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Breaking Changes | Last major release (v6.0.0) dropped PHP 7.3 and renamed a class. | Audit dependencies; test with PHP 8.0+ before adoption. |
| Laravel Integration | No native Laravel support; requires custom adapters for events/jobs. | Build thin wrapper classes to bridge Laravel events ↔ SimpleBus messages. |
| Performance Overhead | Serialization/deserialization adds latency. | Benchmark against Laravel’s native json_encode(); optimize if critical. |
| Maintenance Burden | Abandoned since 2021 (no recent activity). | Fork or monitor for security updates; consider alternatives (e.g., Symfony Serializer). |
| Testing Complexity | May require mocking serializers in unit tests. | Use Laravel’s testing tools to verify message serialization/deserialization. |
Why Serialization Standardization?
Laravel-Specific Needs
json_encode() for events/jobs?Alternatives
Long-Term Viability
| Laravel Component | Integration Strategy |
|---|---|
| Events | Create adapters to convert Laravel events ↔ SimpleBus messages (e.g., EventToMessage). |
| Queued Jobs | Serialize job payloads using the package before dispatching (e.g., Bus::dispatch()). |
| API Requests/Responses | Use for standardizing payload serialization in controllers/middleware. |
| Database Storage | Store serialized messages in JSON columns (e.g., messages table with payload field). |
| External Services | Bridge between Laravel and SimpleBus-compatible microservices. |
Assessment Phase
json_encode() in jobs/events).Proof of Concept (PoC)
Incremental Rollout
json_encode() in new features with SimpleBus serializers.Adapter Layer
class LaravelEventToMessageAdapter
{
public function __construct(private Serializer $serializer) {}
public function adapt(Event $event): Message
{
return new Message(
$this->serializer->serialize($event),
$event::class
);
}
}
beberlei/assert (removed in v6.0.0).composer require simple-bus/serialization:^6.2
$serializer = new JsonSerializer(); // or XmlSerializer, etc.
EventToMessage and MessageToEvent.JobPayloadSerializer.// Instead of:
event(new UserCreated($user));
// Use:
$message = $adapter->adapt(new UserCreated($user));
Bus::dispatch($message);
dd() or Xdebug for adapter debugging.json_encode() (SimpleBus may add ~10-30% overhead).LONGTEXT for JSON).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Serialization Error | Message loss/corruption | Implement retry logic with fallback to native JSON. |
| Deserialization Failure | Job/event processing halt | Validate payloads before dispatching; use try-catch blocks. |
| PHP Version Incompatibility | Deployment blocker | Pin to a supported version in composer.json. |
| Adapter Bug | Data corruption | Unit test adapters with edge cases (e.g., nested objects, null values). |
| Package Abandonment | Security vulnerabilities | Fork the repo or migrate to Symfony Serializer. |
How can I help you explore Laravel packages today?