mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
Simplify Predis\Profiles\ServerProfile::defineCommand().
This commit is contained in:
+1
-1
@@ -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();
|
||||
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user