瀏覽代碼

Merge branch 'protocols'

Daniele Alessandri 14 年之前
父節點
當前提交
44d4c77918

+ 1 - 1
lib/Predis/Network/ComposableStreamConnection.php

@@ -6,7 +6,7 @@ use Predis\IConnectionParameters;
 use Predis\CommunicationException;
 use Predis\Commands\ICommand;
 use Predis\Protocols\IProtocolProcessor;
-use Predis\Protocols\TextProtocol;
+use Predis\Protocols\Text\TextProtocol;
 
 class ComposableStreamConnection extends StreamConnection implements IConnectionComposable {
     private $_protocol;

+ 1 - 1
lib/Predis/Protocols/IProtocolProcessorExtended.php → lib/Predis/Protocols/IComposableProtocolProcessor.php

@@ -2,7 +2,7 @@
 
 namespace Predis\Protocols;
 
-interface IProtocolProcessorExtended extends IProtocolProcessor {
+interface IComposableProtocolProcessor extends IProtocolProcessor {
     public function setSerializer(ICommandSerializer $serializer);
     public function getSerializer();
     public function setReader(IResponseReader $reader);

+ 1 - 2
lib/Predis/Protocols/IProtocolProcessor.php

@@ -5,8 +5,7 @@ namespace Predis\Protocols;
 use Predis\Commands\ICommand;
 use Predis\Network\IConnectionComposable;
 
-interface IProtocolProcessor {
+interface IProtocolProcessor extends IResponseReader {
     public function write(IConnectionComposable $connection, ICommand $command);
-    public function read(IConnectionComposable $connection);
     public function setOption($option, $value);
 }

+ 3 - 2
lib/Predis/Protocols/IResponseReader.php

@@ -2,7 +2,8 @@
 
 namespace Predis\Protocols;
 
+use Predis\Network\IConnectionComposable;
+
 interface IResponseReader {
-    public function setHandler($prefix, IResponseHandler $handler);
-    public function getHandler($prefix);
+    public function read(IConnectionComposable $connection);
 }

+ 5 - 2
lib/Predis/Protocols/ComposableTextProtocol.php → lib/Predis/Protocols/Text/ComposableTextProtocol.php

@@ -1,11 +1,14 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Commands\ICommand;
+use Predis\Protocols\IResponseReader;
+use Predis\Protocols\ICommandSerializer;
+use Predis\Protocols\IComposableProtocolProcessor;
 use Predis\Network\IConnectionComposable;
 
-class ComposableTextProtocol implements IProtocolProcessorExtended {
+class ComposableTextProtocol implements IComposableProtocolProcessor {
     private $_serializer, $_reader;
 
     public function __construct(Array $options = array()) {

+ 2 - 1
lib/Predis/Protocols/ResponseBulkHandler.php → lib/Predis/Protocols/Text/ResponseBulkHandler.php

@@ -1,9 +1,10 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
 use Predis\ProtocolException;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseBulkHandler implements IResponseHandler {

+ 2 - 1
lib/Predis/Protocols/ResponseErrorHandler.php → lib/Predis/Protocols/Text/ResponseErrorHandler.php

@@ -1,8 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\ServerException;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseErrorHandler implements IResponseHandler {

+ 2 - 1
lib/Predis/Protocols/ResponseErrorSilentHandler.php → lib/Predis/Protocols/Text/ResponseErrorSilentHandler.php

@@ -1,8 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\ResponseError;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseErrorSilentHandler implements IResponseHandler {

+ 2 - 2
lib/Predis/Protocols/ResponseIntegerHandler.php → lib/Predis/Protocols/Text/ResponseIntegerHandler.php

@@ -1,9 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
-use Predis\ProtocolException;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseIntegerHandler implements IResponseHandler {

+ 2 - 2
lib/Predis/Protocols/ResponseMultiBulkHandler.php → lib/Predis/Protocols/Text/ResponseMultiBulkHandler.php

@@ -1,9 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
-use Predis\ProtocolException;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseMultiBulkHandler implements IResponseHandler {

+ 2 - 1
lib/Predis/Protocols/ResponseMultiBulkStreamHandler.php → lib/Predis/Protocols/Text/ResponseMultiBulkStreamHandler.php

@@ -1,9 +1,10 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
 use Predis\ProtocolException;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 use Predis\Iterators\MultiBulkResponseSimple;
 

+ 2 - 1
lib/Predis/Protocols/ResponseStatusHandler.php → lib/Predis/Protocols/Text/ResponseStatusHandler.php

@@ -1,8 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\ResponseQueued;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class ResponseStatusHandler implements IResponseHandler {

+ 2 - 1
lib/Predis/Protocols/TextCommandSerializer.php → lib/Predis/Protocols/Text/TextCommandSerializer.php

@@ -1,8 +1,9 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Commands\ICommand;
+use Predis\Protocols\ICommandSerializer;
 
 class TextCommandSerializer implements ICommandSerializer {
     public function serialize(ICommand $command) {

+ 2 - 1
lib/Predis/Protocols/TextProtocol.php → lib/Predis/Protocols/Text/TextProtocol.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
 use Predis\ResponseError;
@@ -8,6 +8,7 @@ use Predis\ResponseQueued;
 use Predis\ServerException;
 use Predis\ProtocolException;
 use Predis\Commands\ICommand;
+use Predis\Protocols\IProtocolProcessor;
 use Predis\Network\IConnectionComposable;
 use Predis\Iterators\MultiBulkResponseSimple;
 

+ 3 - 1
lib/Predis/Protocols/TextResponseReader.php → lib/Predis/Protocols/Text/TextResponseReader.php

@@ -1,9 +1,11 @@
 <?php
 
-namespace Predis\Protocols;
+namespace Predis\Protocols\Text;
 
 use Predis\Helpers;
 use Predis\ProtocolException;
+use Predis\Protocols\IResponseReader;
+use Predis\Protocols\IResponseHandler;
 use Predis\Network\IConnectionComposable;
 
 class TextResponseReader implements IResponseReader {

+ 12 - 12
test/ClientFeaturesTest.php

@@ -164,7 +164,7 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
     function testResponseQueued() {
         $response = new \Predis\ResponseQueued();
         $this->assertTrue($response->queued);
-        $this->assertEquals(\Predis\Protocols\TextProtocol::QUEUED, (string)$response);
+        $this->assertEquals(\Predis\Protocols\Text\TextProtocol::QUEUED, (string)$response);
     }
 
 
@@ -280,27 +280,27 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
     /* Predis\Protocols\TextResponseReader */
 
     function testResponseReader_OptionIterableMultiBulkReplies() {
-        $protocol = new Predis\Protocols\ComposableTextProtocol();
+        $protocol = new Predis\Protocols\Text\ComposableTextProtocol();
         $reader = $protocol->getReader();
         $connection = new \Predis\Network\ComposableStreamConnection(RC::getConnectionParameters(), $protocol);
 
         $reader->setHandler(
-            \Predis\Protocols\TextProtocol::PREFIX_MULTI_BULK,
-            new \Predis\Protocols\ResponseMultiBulkHandler()
+            \Predis\Protocols\Text\TextProtocol::PREFIX_MULTI_BULK,
+            new \Predis\Protocols\Text\ResponseMultiBulkHandler()
         );
         $connection->writeBytes("KEYS *\r\n");
         $this->assertInternalType('array', $reader->read($connection));
 
         $reader->setHandler(
-            \Predis\Protocols\TextProtocol::PREFIX_MULTI_BULK, 
-            new \Predis\Protocols\ResponseMultiBulkStreamHandler()
+            \Predis\Protocols\Text\TextProtocol::PREFIX_MULTI_BULK,
+            new \Predis\Protocols\Text\ResponseMultiBulkStreamHandler()
         );
         $connection->writeBytes("KEYS *\r\n");
         $this->assertInstanceOf('\Iterator', $reader->read($connection));
     }
 
     function testResponseReader_OptionExceptionOnError() {
-        $protocol = new Predis\Protocols\ComposableTextProtocol();
+        $protocol = new Predis\Protocols\Text\ComposableTextProtocol();
         $reader = $protocol->getReader();
         $connection = new \Predis\Network\ComposableStreamConnection(RC::getConnectionParameters(), $protocol);
 
@@ -309,8 +309,8 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $reader->read($connection);
 
         $reader->setHandler(
-            \Predis\Protocols\TextProtocol::PREFIX_ERROR,
-            new \Predis\Protocols\ResponseErrorSilentHandler()
+            \Predis\Protocols\Text\TextProtocol::PREFIX_ERROR,
+            new \Predis\Protocols\Text\ResponseErrorSilentHandler()
         );
         $connection->writeBytes($rawCmdUnexpected);
         $errorReply = $reader->read($connection);
@@ -318,8 +318,8 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
 
         $reader->setHandler(
-            \Predis\Protocols\TextProtocol::PREFIX_ERROR,
-            new \Predis\Protocols\ResponseErrorHandler()
+            \Predis\Protocols\Text\TextProtocol::PREFIX_ERROR,
+            new \Predis\Protocols\Text\ResponseErrorHandler()
         );
         RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function()
             use ($connection, $rawCmdUnexpected) {
@@ -330,7 +330,7 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
     }
 
     function testResponseReader_EmptyBulkResponse() {
-        $protocol = new \Predis\Protocols\ComposableTextProtocol();
+        $protocol = new \Predis\Protocols\Text\ComposableTextProtocol();
         $connection = new \Predis\Network\ComposableStreamConnection(RC::getConnectionParameters(), $protocol);
         $client = new \Predis\Client($connection);