PHP code example of cognesy / instructor-events

1. Go to this page and download the library: Download cognesy/instructor-events 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/ */

    

cognesy / instructor-events example snippets




use Cognesy\Events\Dispatchers\EventDispatcher;
use Cognesy\Events\Event;

final class UserLoggedIn extends Event {}

$events = new EventDispatcher();

$events->addListener(UserLoggedIn::class, function (UserLoggedIn $event): void {
    // handle typed event
});

$events->wiretap(function (object $event): void {
    // observe every event
});

$events->dispatch(new UserLoggedIn(['userId' => 123]));