Simplify Predis\Profiles\ServerProfile::defineCommand().

This commit is contained in:
Daniele Alessandri
2011-04-04 15:03:14 +02:00
parent bfa9cc7469
commit da2cd3ee7e
3 changed files with 6 additions and 15 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ client instance at runtime. Actually, it is easier done than said:
}
$redis = new Predis\Client();
$redis->getProfile()->defineCommand('BrandNewRedisCommand', 'newcmd');
$redis->getProfile()->defineCommand('newcmd', 'BrandNewRedisCommand');
$redis->newcmd();
+4 -13
View File
@@ -89,26 +89,17 @@ abstract class ServerProfile implements IServerProfile {
}
public function defineCommands(Array $commands) {
foreach ($commands as $command => $aliases) {
$this->defineCommand($command, $aliases);
foreach ($commands as $alias => $command) {
$this->defineCommand($alias, $command);
}
}
public function defineCommand($command, $aliases) {
public function defineCommand($alias, $command) {
$commandReflection = new \ReflectionClass($command);
if (!$commandReflection->isSubclassOf('\Predis\Commands\ICommand')) {
throw new ClientException("Cannot register '$command' as it is not a valid Redis command");
}
if (is_array($aliases)) {
foreach ($aliases as $alias) {
$this->_registeredCommands[$alias] = $command;
}
}
else {
$this->_registeredCommands[$aliases] = $command;
}
$this->_registeredCommands[$alias] = $command;
}
public function __toString() {
+1 -1
View File
@@ -153,7 +153,7 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
$cmdClass = '\Predis\Commands\Multi';
$this->assertFalse($profile->supportsCommand($cmdId));
$profile->defineCommand(new $cmdClass(), $cmdId);
$profile->defineCommand($cmdId, new $cmdClass());
$this->assertTrue($profile->supportsCommand($cmdId));
$this->assertInstanceOf($cmdClass, $profile->createCommand($cmdId));
}