public function handleMessage(ModelInterface $message)
{
$this->emit('data', array($message));
if ($this->monitoring && $this->isMonitorMessage($message)) {
$this->emit('monitor', array($message));
return;
}
if (($this->subscribed !== 0 || $this->psubscribed !== 0) && $message instanceof MultiBulkReply) {
$array = $message->getValueNative();
$first = array_shift($array);
// pub/sub messages are to be forwarded and should not be processed as request responses
if (in_array($first, array('message', 'pmessage'))) {
$this->emit($first, $array);
return;
}
}
if (!$this->requests) {
throw new UnderflowException('Unexpected reply received, no matching request found');
}
$request = array_shift($this->requests);
/* @var $request Deferred */
if ($message instanceof ErrorReply) {
$request->reject($message);
} else {
$request->resolve($message->getValueNative());
}
if ($this->ending && !$this->isBusy()) {
$this->close();
}
}