PHP code example of mamuz / message-bridge

1. Go to this page and download the library: Download mamuz/message-bridge 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/ */

    

mamuz / message-bridge example snippets


// Register dispatch callback globally
set_message_dispatcher(function ($msg, $argv, $emitter) {
    if ($msg == 'user.registered') {
        mail('[email protected]', 'A new user entered', 'UserId ' . $argv['userId']);
    }
});

// Trigger any message anywhere
trigger_message('user.registered', array('userId' => 1234));

$bridge = \MsgBridge\MessageBridge::getInstance();
$bridge->bindDispatcher(function ($msg, $argv, $emitter) use ($eventManager) {
    $eventManager->trigger($msg, $argv, $emitter);
});

// ...

$bridge->trigger('user.registered', array('userId' => 1234));

$locked = true;
set_message_dispatcher($closure, $locked);

// This will throw a RuntimeException now
set_message_dispatcher($anotherClosure);

public function tearDown()
{
    \MsgBridge\MessageBridge::getInstance()->unsetDispatcher();
}
xml
<phpunit>
    <listeners>
        <listener class="\MsgBridge\TestListener"></listener>
    </listeners>
</phpunit>