diff --git a/README.markdown b/README.markdown index 089d20d5..a80cb402 100644 --- a/README.markdown +++ b/README.markdown @@ -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(); diff --git a/lib/Predis/Profiles/ServerProfile.php b/lib/Predis/Profiles/ServerProfile.php index 6a8f3c69..1cb91600 100644 --- a/lib/Predis/Profiles/ServerProfile.php +++ b/lib/Predis/Profiles/ServerProfile.php @@ -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() { diff --git a/test/ClientFeaturesTest.php b/test/ClientFeaturesTest.php index 9413b6e6..5cbc8812 100644 --- a/test/ClientFeaturesTest.php +++ b/test/ClientFeaturesTest.php @@ -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)); }