1. Go to this page and download the library: Download laxity7/yii2-event-service 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/ */
laxity7 / yii2-event-service example snippets
namespace App\Events;
use yii\base\Event;
final readonly class PaymentEvent
{
public function __construct(
public float $amount,
public string $currency,
public string $description,
) {
}
}
namespace App\Events\listeners;
use App\Events\PaymentEvent;
final class PaymentListener
{
//public function __invoke(PaymentEvent $event): void
public function handle(PaymentEvent $event): void
{
Yii::info('Event: ' . get_class($event) . ' Trigger: ' . __METHOD__, __METHOD__);
}
}
use App\Events\PaymentEvent;
use Laxity7\Yii2\Components\Event;
$event = new PaymentEvent(100, 'USD', 'Payment for goods');
\Yii::$app->eventDispatcher->dispatch($event);
// or use the helper
Event::dispatch($event);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.