mirror of
https://github.com/predis/predis.git
synced 2026-08-21 03:32:26 +00:00
Change Predis\Commands\Preprocessors to Predis\Command\Processors.
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
require 'SharedConfigurations.php';
|
||||
|
||||
// Predis ships with a KeyPrefixPreprocessor class that is used to transparently
|
||||
// Predis ships with a KeyPrefixProcessor class that is used to transparently
|
||||
// prefix each key before sending commands to Redis, even for complex commands
|
||||
// such as SORT, ZUNIONSTORE and ZINTERSTORE. Key prefixes are useful to create
|
||||
// user-level namespaces for you keyspace, thus eliminating the need for separate
|
||||
// logical databases.
|
||||
|
||||
use Predis\Commands\Preprocessors\KeyPrefixPreprocessor;
|
||||
use Predis\Commands\Processors\KeyPrefixProcessor;
|
||||
|
||||
$client = new Predis\Client();
|
||||
$client->getProfile()->setPreprocessor(new KeyPrefixPreprocessor('nrk:'));
|
||||
$client->getProfile()->setProcessor(new KeyPrefixProcessor('nrk:'));
|
||||
|
||||
$client->mset(array('foo' => 'bar', 'lol' => 'wut'));
|
||||
var_dump($client->mget('foo', 'lol'));
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
interface ICommandPreprocessor {
|
||||
public function process($method, &$arguments);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
interface ICommandPreprocessorChain
|
||||
extends ICommandPreprocessor, \IteratorAggregate, \Countable {
|
||||
|
||||
public function add(ICommandPreprocessor $preprocessor);
|
||||
public function remove(ICommandPreprocessor $preprocessor);
|
||||
public function getPreprocessors();
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
interface IPreprocessingSupport {
|
||||
public function setPreprocessor(ICommandPreprocessor $processor);
|
||||
public function getPreprocessor();
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
|
||||
class PreprocessorChain implements ICommandPreprocessorChain, \ArrayAccess {
|
||||
private $_preprocessors;
|
||||
|
||||
public function __construct($preprocessors = array()) {
|
||||
foreach ($preprocessors as $preprocessor) {
|
||||
$this->add($preprocessor);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(ICommandPreprocessor $preprocessor) {
|
||||
$this->_preprocessors[] = $preprocessor;
|
||||
}
|
||||
|
||||
public function remove(ICommandPreprocessor $preprocessor) {
|
||||
$index = array_search($preprocessor, $this->_preprocessors, true);
|
||||
if ($index !== false) {
|
||||
unset($this->_preprocessors);
|
||||
}
|
||||
}
|
||||
|
||||
public function process($method, &$arguments) {
|
||||
$count = count($this->_preprocessors);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->_preprocessors[$i]->process($method, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPreprocessors() {
|
||||
return $this->_preprocessors;
|
||||
}
|
||||
|
||||
public function getIterator() {
|
||||
return new \ArrayIterator($this->_preprocessors);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->_preprocessors);
|
||||
}
|
||||
|
||||
public function offsetExists($index) {
|
||||
return isset($this->_preprocessors[$index]);
|
||||
}
|
||||
|
||||
public function offsetGet($index) {
|
||||
return $this->_preprocessors[$index];
|
||||
}
|
||||
|
||||
public function offsetSet($index, $preprocessor) {
|
||||
if (!$preprocessor instanceof ICommandPreprocessor) {
|
||||
throw new \InvalidArgumentException(
|
||||
'A preprocessor chain can hold only instances of classes implementing '.
|
||||
'the Predis\Commands\Preprocessors\ICommandPreprocessor interface'
|
||||
);
|
||||
}
|
||||
$this->_preprocessors[$index] = $preprocessor;
|
||||
}
|
||||
|
||||
public function offsetUnset($index) {
|
||||
unset($this->_preprocessors[$index]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Processors;
|
||||
|
||||
interface ICommandProcessor {
|
||||
public function process($method, &$arguments);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Processors;
|
||||
|
||||
interface ICommandProcessorChain
|
||||
extends ICommandProcessor, \IteratorAggregate, \Countable {
|
||||
|
||||
public function add(ICommandProcessor $preprocessor);
|
||||
public function remove(ICommandProcessor $preprocessor);
|
||||
public function getProcessors();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Processors;
|
||||
|
||||
interface IProcessingSupport {
|
||||
public function setProcessor(ICommandProcessor $processor);
|
||||
public function getProcessor();
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Preprocessors;
|
||||
namespace Predis\Commands\Processors;
|
||||
|
||||
use Predis\ClientException;
|
||||
use Predis\Profiles\IServerProfile;
|
||||
|
||||
class KeyPrefixPreprocessor implements ICommandPreprocessor {
|
||||
class KeyPrefixProcessor implements ICommandProcessor {
|
||||
private $_prefix;
|
||||
private $_strategies;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Commands\Processors;
|
||||
|
||||
class ProcessorChain implements ICommandProcessorChain, \ArrayAccess {
|
||||
private $_processors;
|
||||
|
||||
public function __construct($processors = array()) {
|
||||
foreach ($processors as $processor) {
|
||||
$this->add($processor);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(ICommandProcessor $processor) {
|
||||
$this->_processors[] = $processor;
|
||||
}
|
||||
|
||||
public function remove(ICommandProcessor $processor) {
|
||||
$index = array_search($processor, $this->_processors, true);
|
||||
if ($index !== false) {
|
||||
unset($this->_processors);
|
||||
}
|
||||
}
|
||||
|
||||
public function process($method, &$arguments) {
|
||||
$count = count($this->_processors);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->_processors[$i]->process($method, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public function getProcessors() {
|
||||
return $this->_processors;
|
||||
}
|
||||
|
||||
public function getIterator() {
|
||||
return new \ArrayIterator($this->_processors);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->_processors);
|
||||
}
|
||||
|
||||
public function offsetExists($index) {
|
||||
return isset($this->_processors[$index]);
|
||||
}
|
||||
|
||||
public function offsetGet($index) {
|
||||
return $this->_processors[$index];
|
||||
}
|
||||
|
||||
public function offsetSet($index, $processor) {
|
||||
if (!$processor instanceof ICommandProcessor) {
|
||||
throw new \InvalidArgumentException(
|
||||
'A processor chain can hold only instances of classes implementing '.
|
||||
'the Predis\Commands\Preprocessors\ICommandProcessor interface'
|
||||
);
|
||||
}
|
||||
$this->_processors[$index] = $processor;
|
||||
}
|
||||
|
||||
public function offsetUnset($index) {
|
||||
unset($this->_processors[$index]);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
namespace Predis\Profiles;
|
||||
|
||||
use Predis\ClientException;
|
||||
use Predis\Commands\Preprocessors\ICommandPreprocessor;
|
||||
use Predis\Commands\Preprocessors\IPreprocessingSupport;
|
||||
use Predis\Commands\Processors\ICommandProcessor;
|
||||
use Predis\Commands\Processors\IProcessingSupport;
|
||||
|
||||
abstract class ServerProfile implements IServerProfile, IPreprocessingSupport {
|
||||
abstract class ServerProfile implements IServerProfile, IProcessingSupport {
|
||||
private static $_profiles;
|
||||
private $_registeredCommands;
|
||||
private $_preprocessor;
|
||||
private $_processor;
|
||||
|
||||
public function __construct() {
|
||||
$this->_registeredCommands = $this->getSupportedCommands();
|
||||
@@ -76,8 +76,8 @@ abstract class ServerProfile implements IServerProfile, IPreprocessingSupport {
|
||||
if (!isset($this->_registeredCommands[$method])) {
|
||||
throw new ClientException("'$method' is not a registered Redis command");
|
||||
}
|
||||
if (isset($this->_preprocessor)) {
|
||||
$this->_preprocessor->process($method, $arguments);
|
||||
if (isset($this->_processor)) {
|
||||
$this->_processor->process($method, $arguments);
|
||||
}
|
||||
$commandClass = $this->_registeredCommands[$method];
|
||||
$command = new $commandClass();
|
||||
@@ -99,16 +99,16 @@ abstract class ServerProfile implements IServerProfile, IPreprocessingSupport {
|
||||
$this->_registeredCommands[$alias] = $command;
|
||||
}
|
||||
|
||||
public function setPreprocessor(ICommandPreprocessor $preprocessor) {
|
||||
if (!isset($preprocessor)) {
|
||||
unset($this->_preprocessor);
|
||||
public function setProcessor(ICommandProcessor $processor) {
|
||||
if (!isset($processor)) {
|
||||
unset($this->_processor);
|
||||
return;
|
||||
}
|
||||
$this->_preprocessor = $preprocessor;
|
||||
$this->_processor = $processor;
|
||||
}
|
||||
|
||||
public function getPreprocessor() {
|
||||
return $this->_preprocessor;
|
||||
public function getProcessor() {
|
||||
return $this->_processor;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
|
||||
Reference in New Issue
Block a user