PHP code example of dhenfie / event-dispatcher

1. Go to this page and download the library: Download dhenfie/event-dispatcher 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/ */

    

dhenfie / event-dispatcher example snippets



// file SendToEmail.php
use Dhenfie\EventDispatcher\EventDispatcher;

class SendToEmail implements EventListenerInterface {
 
    public function handle(array $params = []) {
        // send an email to the user
        Mail::send($params['email'], $params['message']);
    }
}


use Dhenfie\EventDispatcher\EventDispatcher;
use SendToEmail;

// daftarkan pendengar menggunakan static method `listen`
EventDispatcher::listen('passwordRequestSend', new SendToEmail());


use Dhenfie\EventDispatcher\EventDispatcher;

// trigger event passwordRequestSend
EventDispatcher::dispatch('passwordRequestSend');



use Dhenfie\EventDispatcher\EventDispatcher;

EventDispatcher::dispatch('passwordRequestSend', ['email' => '[email protected]', 'message' => 'Your password reset token we send your email']);