Remove useless helpers.

This commit is contained in:
Daniele Alessandri
2012-07-25 21:18:58 +02:00
parent 89d6c0e9b6
commit c3cafaa9a6
6 changed files with 17 additions and 48 deletions
+5 -3
View File
@@ -14,6 +14,7 @@ namespace Predis;
use Predis\Command\CommandInterface;
use Predis\Option\ClientOptionsInterface;
use Predis\Connection\ConnectionInterface;
use Predis\Connection\AggregatedConnectionInterface;
use Predis\Profile\ServerProfileInterface;
use Predis\Option\ClientOptions;
use Predis\Profile\ServerProfile;
@@ -187,9 +188,10 @@ class Client implements ClientInterface
public function getConnection($id = null)
{
if (isset($id)) {
if (!Helpers::isAggregated($this->connection)) {
$message = 'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)';
throw new NotSupportedException($message);
if (!$this->connection instanceof AggregatedConnectionInterface) {
throw new NotSupportedException(
'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)'
);
}
return $this->connection->getConnectionById($id);
}
-22
View File
@@ -22,28 +22,6 @@ use Predis\Connection\AggregatedConnectionInterface;
*/
class Helpers
{
/**
* Checks if the specified connection represents an aggregation of connections.
*
* @param ConnectionInterface $connection Connection object.
* @return Boolean
*/
public static function isAggregated(ConnectionInterface $connection)
{
return $connection instanceof AggregatedConnectionInterface;
}
/**
* Checks if the specified connection represents a cluster.
*
* @param ConnectionInterface $connection Connection object.
* @return Boolean
*/
public static function isCluster(ConnectionInterface $connection)
{
return $connection instanceof ClusterConnectionInterface;
}
/**
* Offers a generic and reusable method to handle exceptions generated by
* a connection object.
+2 -2
View File
@@ -12,8 +12,8 @@
namespace Predis\Monitor;
use Predis\ClientInterface;
use Predis\Helpers;
use Predis\NotSupportedException;
use Predis\Connection\AggregatedConnectionInterface;
/**
* Client-side abstraction of a Redis MONITOR context.
@@ -52,7 +52,7 @@ class MonitorContext implements \Iterator
*/
private function checkCapabilities(ClientInterface $client)
{
if (Helpers::isCluster($client->getConnection())) {
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a monitor context over a cluster of connections');
}
+2 -1
View File
@@ -15,6 +15,7 @@ use Predis\ClientInterface;
use Predis\Helpers;
use Predis\ClientException;
use Predis\NotSupportedException;
use Predis\Connection\AggregatedConnectionInterface;
/**
* Client-side abstraction of a Publish / Subscribe context.
@@ -48,7 +49,7 @@ class PubSubContext extends AbstractPubSubContext
*/
private function checkCapabilities(ClientInterface $client)
{
if (Helpers::isCluster($client->getConnection())) {
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a PUB/SUB context over a cluster of connections');
}
+8 -8
View File
@@ -17,7 +17,7 @@ use Predis\BasicClientInterface;
use Predis\ExecutableContextInterface;
use Predis\ResponseErrorInterface;
use Predis\Command\CommandInterface;
use Predis\Helpers;
use Predis\Connection\AggregatedConnectionInterface;
use Predis\ResponseQueued;
use Predis\ClientException;
use Predis\ServerException;
@@ -32,12 +32,12 @@ use Predis\Protocol\ProtocolException;
*/
class MultiExecContext implements BasicClientInterface, ExecutableContextInterface
{
const STATE_RESET = 0; // 0b00000
const STATE_INITIALIZED = 1; // 0b00001
const STATE_INSIDEBLOCK = 2; // 0b00010
const STATE_DISCARDED = 4; // 0b00100
const STATE_CAS = 8; // 0b01000
const STATE_WATCH = 16; // 0b10000
const STATE_RESET = 0; // 0b00000
const STATE_INITIALIZED = 1; // 0b00001
const STATE_INSIDEBLOCK = 2; // 0b00010
const STATE_DISCARDED = 4; // 0b00100
const STATE_CAS = 8; // 0b01000
const STATE_WATCH = 16; // 0b10000
private $state;
private $canWatch;
@@ -117,7 +117,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
*/
private function checkCapabilities(ClientInterface $client)
{
if (Helpers::isCluster($client->getConnection())) {
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a MULTI/EXEC context over a cluster of connections');
}
-12
View File
@@ -18,18 +18,6 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
*/
class HelpersTest extends StandardTestCase
{
/**
* @group disconnected
*/
public function testConnectionIsCluster()
{
$single = $this->getMock('Predis\Connection\SingleConnectionInterface');
$cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface');
$this->assertFalse(Helpers::isCluster($single));
$this->assertTrue(Helpers::isCluster($cluster));
}
/**
* @group disconnected
*/