Add an abstraction to optionally preprocess command arguments.

This commit is contained in:
Daniele Alessandri
2011-04-05 11:56:36 +02:00
parent c0d9b53ff7
commit 07b4238ce7
3 changed files with 34 additions and 1 deletions
@@ -0,0 +1,7 @@
<?php
namespace Predis\Commands\Preprocessors;
interface ICommandPreprocessor {
public function process(&$method, &$arguments);
}
@@ -0,0 +1,8 @@
<?php
namespace Predis\Commands\Preprocessors;
interface IPreprocessingSupport {
public function setPreprocessor(ICommandPreprocessor $processor);
public function getPreprocessor();
}
+19 -1
View File
@@ -3,10 +3,13 @@
namespace Predis\Profiles;
use Predis\ClientException;
use Predis\Commands\Preprocessors\ICommandPreprocessor;
use Predis\Commands\Preprocessors\IPreprocessingSupport;
abstract class ServerProfile implements IServerProfile {
abstract class ServerProfile implements IServerProfile, IPreprocessingSupport {
private static $_profiles;
private $_registeredCommands;
private $_preprocessor;
public function __construct() {
$this->_registeredCommands = $this->getSupportedCommands();
@@ -70,6 +73,9 @@ abstract class ServerProfile implements IServerProfile {
}
public function createCommand($method, $arguments = array()) {
if (isset($this->_preprocessor)) {
$this->_preprocessor->process($method, $arguments);
}
if (!isset($this->_registeredCommands[$method])) {
throw new ClientException("'$method' is not a registered Redis command");
}
@@ -93,6 +99,18 @@ abstract class ServerProfile implements IServerProfile {
$this->_registeredCommands[$alias] = $command;
}
public function setPreprocessor(ICommandPreprocessor $preprocessor) {
if (!isset($preprocessor)) {
unset($this->_preprocessor);
return;
}
$this->_preprocessor = $preprocessor;
}
public function getPreprocessor() {
return $this->_preprocessor;
}
public function __toString() {
return $this->getVersion();
}