瀏覽代碼

Predis\PubSub\DispatcherLoop should take a PubSub consumer instance.

Daniele Alessandri 10 年之前
父節點
當前提交
b230e243f5
共有 4 個文件被更改,包括 17 次插入9 次删除
  1. 3 0
      CHANGELOG.md
  2. 6 3
      examples/dispatcher_loop.php
  3. 3 4
      src/PubSub/DispatcherLoop.php
  4. 5 2
      tests/Predis/PubSub/DispatcherLoopTest.php

+ 3 - 0
CHANGELOG.md

@@ -74,6 +74,9 @@ v1.0.0 (201x-xx-xx)
   they can also define the needed logic in their command classes by implementing
   `Predis\Command\PrefixableCommandInterface` just like before.
 
+- `Predis\PubSub\DispatcherLoop` now takes a `Predis\PubSub\Consumer` instance
+  as the sole argument of its constructor instead of `Predis\ClientInterface`.
+
 - All of the interfaces and classes related to translated Redis response types
   have been moved in the new `Predis\Response` namespace and most of them have
   been renamed to make their fully-qualified name less redundant. Now the base

+ 6 - 3
examples/dispatcher_loop.php

@@ -25,10 +25,13 @@ require __DIR__.'/shared.php';
 // Create a client and disable r/w timeout on the socket
 $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
 
-// Create a Predis\DispatcherLoop instance and attach a bunch of callbacks.
-$dispatcher = new Predis\PubSub\DispatcherLoop($client);
+// Return an initialized PubSub consumer instance from the client.
+$pubsub = $client->pubSubLoop();
 
-// Demonstrate how to use a callable class as a callback for Predis\DispatcherLoop.
+// Create a dispatcher loop instance and attach a bunch of callbacks.
+$dispatcher = new Predis\PubSub\DispatcherLoop($pubsub);
+
+// Demonstrate how to use a callable class as a callback for the dispatcher loop.
 class EventsListener implements Countable
 {
     private $events;

+ 3 - 4
src/PubSub/DispatcherLoop.php

@@ -12,7 +12,6 @@
 namespace Predis\PubSub;
 
 use InvalidArgumentException;
-use Predis\ClientInterface;
 
 /**
  * Method-dispatcher loop built around the client-side abstraction of a Redis
@@ -29,12 +28,12 @@ class DispatcherLoop
     protected $subscriptionCallback;
 
     /**
-     * @param ClientInterface $client Client instance used by the context.
+     * @param Consumer $pubsub PubSub consumer instance used by the loop.
      */
-    public function __construct(ClientInterface $client)
+    public function __construct(Consumer $pubsub)
     {
         $this->callbacks = array();
-        $this->pubsub = $client->pubSubLoop();
+        $this->pubsub = $pubsub;
     }
 
     /**

+ 5 - 2
tests/Predis/PubSub/DispatcherLoopTest.php

@@ -44,7 +44,8 @@ class DispatcherLoopTest extends PredisTestCase
         $consumer = new Client($parameters, $options);
         $consumer->connect();
 
-        $dispatcher = new DispatcherLoop($consumer);
+        $pubsub = new Consumer($consumer);
+        $dispatcher = new DispatcherLoop($pubsub);
 
         $function01 = $this->getMock('stdClass', array('__invoke'));
         $function01->expects($this->exactly(2))
@@ -103,7 +104,9 @@ class DispatcherLoopTest extends PredisTestCase
         $producerPfx->connect();
 
         $consumer = new Client($parameters, $options + array('prefix' => 'foobar'));
-        $dispatcher = new DispatcherLoop($consumer);
+
+        $pubsub = new Consumer($consumer);
+        $dispatcher = new DispatcherLoop($pubsub);
 
         $callback = $this->getMock('stdClass', array('__invoke'));
         $callback->expects($this->exactly(1))