Skip to content

Instantly share code, notes, and snippets.

@dgafka
Last active November 19, 2022 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgafka/c86dabc6369856c3dd9848a1af76667f to your computer and use it in GitHub Desktop.
Save dgafka/c86dabc6369856c3dd9848a1af76667f to your computer and use it in GitHub Desktop.
testing-message-driven-architecture-in-php-01
<?php
class OrderService
{
#[CommandHandler]
public function place(PlaceOrder $placeOrder, OrderRepository $orderRepository, EventBus $eventBus): void
{
$orderRepository->save(Order::from($placeOrder));
$eventBus->publish(new OrderWasPlaced($placeOrder->getOrderId()), []);
}
}
class OrderNotifier
{
#[Asynchronous('notifications')]
#[EventHandler(endpointId: "order_notifier")]
public function place(OrderWasPlaced $orderWasPlaced, NotificationService $notificationService): void
{
$notificationService->notifyAboutOrder($orderWasPlaced);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment