/**
  * Creating reply message
  *
  * @param mixed $data to send
  * @param mixed $sender class, object or logical param ($context param)
  * @see \gigi\events\interfaces\SubscriberInterface::subscribe()
  *
  * @return Message
  */
 protected function createReply($data, $sender)
 {
     $replyMessage = new Message(static::REPLY_MESSAGE_NAME, $data);
     $replyMessage->setSender($sender);
     return $replyMessage;
 }
示例#2
0
        Messenger::getInstance()->subscribe('test', ['Subscriber3StaticClass', 'handler'], $priority, $this);
    }
}
class Subscriber3StaticClass
{
    public static function handler($message)
    {
        echo 'Hello from Subscriber3<br>';
        return 'Answer from 3';
    }
}
(new Subscriber1())->init();
(new Subscriber2())->init();
(new Subscriber3())->init();
$message = new Message('test');
$message->setSender('singletonFile');
$handler = Messenger::getInstance();
// some pretty print if you dont have xdebug
echo '<pre>';
echo '----------------<br>';
echo 'First reply only (with priority order)<br>';
var_dump($handler->requestFirstReply($message));
echo '</pre>';
echo '<pre>';
echo '----------------<br>';
echo 'All replies<br>';
// one more time
$message->setIsHandled(false);
$message->removeAllReplies();
var_dump($handler->requestReply($message));
echo '</pre>';