Reorganize the Predis\Protocols namespace.

This commit is contained in:
Daniele Alessandri
2011-04-06 17:52:39 +02:00
parent 80f1cedf79
commit db95350c37
15 changed files with 42 additions and 30 deletions
@@ -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 -2
View File
@@ -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
View File
@@ -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);
}
@@ -1,8 +1,11 @@
<?php
namespace Predis\Protocols;
namespace Predis\Protocols\Text;
use Predis\Commands\ICommand;
use Predis\Protocols\IResponseReader;
use Predis\Protocols\ICommandSerializer;
use Predis\Protocols\IProtocolProcessorExtended;
use Predis\Network\IConnectionComposable;
class ComposableTextProtocol implements IProtocolProcessorExtended {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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;
@@ -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 {
@@ -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) {
@@ -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;
@@ -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
View File
@@ -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);