mirror of
https://github.com/predis/predis.git
synced 2026-09-11 02:46:59 +00:00
Add an abstraction to optionally preprocess command arguments.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user