Implemented a factory method for creating server profiles instances.

This commit is contained in:
Daniele Alessandri
2010-01-23 15:55:34 +01:00
parent afdc79f97f
commit 7fa935f827
2 changed files with 23 additions and 4 deletions
+22 -3
View File
@@ -770,7 +770,7 @@ class ConnectionCluster implements IConnection, \IteratorAggregate {
/* ------------------------------------------------------------------------- */
abstract class RedisServerProfile {
const DEFAULT_SERVER_PROFILE = '\Predis\RedisServer_v1_2';
private static $_serverProfiles;
private $_registeredCommands;
public function __construct() {
@@ -782,8 +782,27 @@ abstract class RedisServerProfile {
protected abstract function getSupportedCommands();
public static function getDefault() {
$defaultProfile = self::DEFAULT_SERVER_PROFILE;
return new $defaultProfile();
return self::get('default');
}
private static function predisServerProfiles() {
return array(
'1.0' => '\Predis\RedisServer_v1_0',
'1.2' => '\Predis\RedisServer_v1_2',
'default' => '\Predis\RedisServer_v1_2',
'dev' => '\Predis\RedisServer_vNext',
);
}
public static function get($version) {
if (!isset(self::$_serverProfiles)) {
self::$_serverProfiles = self::predisServerProfiles();
}
if (!isset(self::$_serverProfiles[$version])) {
throw new ClientException("Unknown server profile: $version");
}
$profile = self::$_serverProfiles[$version];
return new $profile();
}
public function compareWith($version, $operator = null) {
+1 -1
View File
@@ -26,7 +26,7 @@ class RC {
private static $_connection;
private static function createConnection() {
$serverProfile = new Predis\RedisServer_vNext();
$serverProfile = Predis\RedisServerProfile::get('dev');
$connection = new Predis\Client(array('host' => RC::SERVER_HOST, 'port' => RC::SERVER_PORT), $serverProfile);
$connection->connect();
$connection->selectDatabase(RC::DEFAULT_DATABASE);