Sulu\Component\Websocket\MessageDispatcher\MessageDispatcher::add PHP Method

add() public method

public add ( $name, Sulu\Component\Websocket\MessageDispatcher\MessageHandlerInterface $handler )
$handler Sulu\Component\Websocket\MessageDispatcher\MessageHandlerInterface
    public function add($name, MessageHandlerInterface $handler)
    {
        $this->handlers[$name] = $handler;
    }

Usage Example

Example #1
0
 public function testOnClose()
 {
     $context = $this->prophesize(MessageHandlerContext::class);
     $conn = $this->prophesize(ConnectionInterface::class);
     $handler1 = $this->prophesize(MessageHandlerInterface::class);
     $handler1->onClose($conn->reveal(), $context->reveal())->shouldBeCalled();
     $handler2 = $this->prophesize(MessageHandlerInterface::class);
     $handler2->onClose($conn->reveal(), $context->reveal())->shouldBeCalled();
     $dispatcher = new MessageDispatcher();
     $dispatcher->add('test-1', $handler1->reveal());
     $dispatcher->add('test-2', $handler2->reveal());
     $dispatcher->onClose($conn->reveal(), $context->reveal());
 }