Event Handling PHP
Event Handlers PHP
Demo
Read Blog Post
Code Example
Running The Example
Last updated
Was this helpful?
Event Handlers PHP
Last updated
Was this helpful?
Was this helpful?
class OrderWasPlaced
{
private string $orderId;
private string $productName;
public function __construct(string $orderId, string $productName)
{
$this->orderId = $orderId;
$this->productName = $productName;
}
public function getOrderId(): string
{
return $this->orderId;
}
public function getProductName(): string
{
return $this->productName;
}
}class NotificationService
{
#[EventHandler]
public function notifyAboutNewOrder(OrderWasPlaced $event) : void
{
echo $event->getProductName() . "\n";
}
}$eventBus->publish(new OrderWasPlaced(1, "Milk"));