Skip to content

SomeWork CQRS Bundle

Welcome to the documentation for somework/cqrs-bundle -- a Symfony bundle that wires Command, Query, and Event buses on top of Symfony Messenger.

The bundle auto-discovers handlers via PHP attributes, provides a composable stamp pipeline for retry policies, transport routing, serialization, and metadata, and ships with testing utilities for fast, isolated unit tests.

Highlights

  • Three dedicated buses -- CommandBus, QueryBus, and EventBus with distinct dispatch semantics, available through the CommandBusInterface, QueryBusInterface, and EventBusInterface interfaces.
  • Attribute-based discovery -- Annotate handlers with #[AsCommandHandler], #[AsQueryHandler], or #[AsEventHandler]; they are registered on the synchronous bus and, when configured, the asynchronous bus of their type.
  • Sync or async per message -- Choose per call (DispatchMode), per class (#[Asynchronous]), or in configuration.
  • Stamp pipeline -- Composable StampDecider system with priority ordering. Attach retry policies, transport routing, serializer stamps, and metadata per message class or per message type.
  • Testing utilities -- FakeCommandBus, FakeQueryBus, and FakeEventBus, plus assertDispatched() and assertNotDispatched() with callback-based property assertions.
  • Optional patterns -- Transactional outbox, event ordering, idempotency, rate limiting, causation ID propagation, and OpenTelemetry tracing.

Requirements

  • PHP 8.2 or newer (0.7 will require PHP 8.3)
  • Symfony 7.4 (7.4.9 or newer) or 8.1 and newer

Some features need optional packages: symfony/lock for idempotency, symfony/rate-limiter for rate limiting, doctrine/dbal 4.3+ and doctrine/doctrine-bundle for the transactional outbox, open-telemetry/api 1.8+ for tracing, and PHPUnit 11.5, 12.5 or 13 for the testing helpers.

License

MIT. See LICENSE.