diff --git a/CHANGELOG.md b/CHANGELOG.md index 04df864..620317e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,8 @@ # Changelog -## v0.5.x +## 0.9.x The major change in this version, is that `sagas` are now handled with the `DomainMessage` instead of the `event`. This makes it more consistent with the rest of the broadway framework, where all event listeners are handled with the `DomainMessage`. - - -#### BC breaks - -- The `Saga::handle*()` arguments are reordered with `State`, `event`, `DomainMessage` - -#### Other changes - -- `StaticallyConfiguredSagaInterface::configuration` array of callables gets a second argument which holds the `DomainMessage`. This way it is not necessary to put the identifier in each `event` because you can fetch it from the `DomainMessage` - \ No newline at end of file diff --git a/examples/ReservationSaga.php b/examples/ReservationSaga.php index b2a6db5..78d902e 100644 --- a/examples/ReservationSaga.php +++ b/examples/ReservationSaga.php @@ -54,7 +54,7 @@ public static function configuration() ]; } - public function handleOrderPlaced(State $state, OrderPlaced $event) + public function handleOrderPlaced(OrderPlaced $event, State $state) { // keep the order id, for reference in `handleReservationAccepted()` and `handleReservationRejected()` $state->set('orderId', $event->orderId()); @@ -70,7 +70,7 @@ public function handleOrderPlaced(State $state, OrderPlaced $event) return $state; } - public function handleReservationAccepted(State $state, ReservationAccepted $event) + public function handleReservationAccepted(ReservationAccepted $event, State $state) { // the seat reservation for the given order is has been accepted, mark the order as booked $command = new MarkOrderAsBooked($state->get('orderId')); @@ -82,7 +82,7 @@ public function handleReservationAccepted(State $state, ReservationAccepted $eve return $state; } - public function handleReservationRejected(State $state, ReservationRejected $event) + public function handleReservationRejected(ReservationRejected $event, State $state) { // the seat reservation for the given order is has been rejected, reject the order as well $command = new RejectOrder($state->get('orderId')); diff --git a/src/Saga.php b/src/Saga.php index 2e672ba..b994e26 100644 --- a/src/Saga.php +++ b/src/Saga.php @@ -22,19 +22,18 @@ abstract class Saga implements SagaInterface */ public function handle(DomainMessage $domainMessage, State $state) { - $event = $domainMessage->getPayload(); - $method = $this->getHandleMethod($event); + $method = $this->getHandleMethod($domainMessage); if (!method_exists($this, $method)) { throw new \BadMethodCallException(sprintf("No handle method '%s' for event '%s'.", $method, get_class($event))); } - return $this->$method($state, $event, $domainMessage); + return $this->$method($domainMessage->getPayload(), $state); } - private function getHandleMethod($event) + private function getHandleMethod(DomainMessage $domainMessage) { - $classParts = explode('\\', get_class($event)); + $classParts = explode('\\', get_class($domainMessage->getPayload())); return 'handle'.end($classParts); }