Fix DispatcherLoop error with client prefix keys

DispatcherLoop works properly if a client have configured a
prefix for the keys or not
This commit is contained in:
Eloi Poch
2013-04-20 13:02:17 +02:00
parent d6fa4a3292
commit 6cd124cc59
+19 -3
View File
@@ -96,8 +96,10 @@ class DispatcherLoop
*/
public function attachCallback($channel, $callback)
{
$callbackName = $this->getPrefixKeys() . $channel;
$this->validateCallback($callback);
$this->callbacks[$channel] = $callback;
$this->callbacks[$callbackName] = $callback;
$this->pubSubContext->subscribe($channel);
}
@@ -108,8 +110,10 @@ class DispatcherLoop
*/
public function detachCallback($channel)
{
if (isset($this->callbacks[$channel])) {
unset($this->callbacks[$channel]);
$callbackName = $this->getPrefixKeys() . $channel;
if (isset($this->callbacks[$callbackName])) {
unset($this->callbacks[$callbackName]);
$this->pubSubContext->unsubscribe($channel);
}
}
@@ -148,4 +152,16 @@ class DispatcherLoop
{
$this->pubSubContext->closeContext();
}
/**
* Return the prefix of the keys
*
* @return string
*/
protected function getPrefixKeys()
{
$prefix = $this->client->getOptions()->prefix;
return $prefix ? $prefix->getPrefix() : '';
}
}