1. Go to this page and download the library: Download webware/webware-event library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Webware\Event\EventDispatcherAwareInterface;
use Webware\Event\EventDispatcherAwareTrait;
class OrderService implements EventDispatcherAwareInterface
{
use EventDispatcherAwareTrait;
public function placeOrder(Order $order): void
{
// ...business logic...
$this->eventDispatcher->dispatch(new Event('order.placed', $this, [
'order_id' => $order->id,
]));
}
}