/** * Add the given stream and register it to the EventDispatcher. * * @param string $type * @param StreamInterface $stream * * @return ClientHandler */ protected function setStream($type, StreamInterface $stream) { $this->streams[$type] = $stream; $callback = array($this, 'on' . ucfirst($type) . 'Message'); $stream->addListener(StreamInterface::MESSAGE, $this->createEventListenerForStream($callback)); return $this; }
/** * * @param string $type * @param StreamInterface $stream * * @return WorkerHandler */ protected function setStream($type, $stream) { $this->streams[$type] = $stream; $callback = array($this, 'on' . ucfirst($type) . 'Message'); $logger = $this->getLogger(); $stream->addListener(StreamInterface::MESSAGE, function (MessageEvent $event) use($callback, $logger) { $protocol = $event->getProtocolMessage(); if ($protocol === null) { $logger->debug('Incompatible message: ' . $event->getMessage()); return; } $routing = $event->getMessage()->getRoutingInformation(); call_user_func($callback, $protocol, $routing); return; }); return $this; }