Browse Source

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

Daniele Alessandri 14 years ago
parent
commit
da2cd3ee7e
3 changed files with 6 additions and 15 deletions
  1. 1 1
      README.markdown
  2. 4 13
      lib/Predis/Profiles/ServerProfile.php
  3. 1 1
      test/ClientFeaturesTest.php

+ 1 - 1
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();
 
 

+ 4 - 13
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() {

+ 1 - 1
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));
     }