1. Go to this page and download the library: Download gigi/event-request-response 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/ */
gigi / event-request-response example snippets
use gigi\events\classes\Messenger;
$handler = Messenger::getInstance();
$handler->subscribe('message.test', function ($message) {
// do something with message
// stops further message processing
$message->setIsHandled(true);
// optionally return mixed response
// Will be accessible in reply object (Message::getData())
return 'Data to return';
});
use gigi\events\classes\Message;
$message = new Message('message.test', 'Mixed data to send');
// request-response notifier
// Returns only first reply (Message object)
// Use if Your don't care of who can return an answer
// for example if you want to get list of all users ('users.get.all')
// or you know for sure that only one subscriber listening
$result = $handler->requestFirstReply($message);