From 09b5d7ac61edcc080baceaadabd6ef8e58207ffb Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Wed, 4 May 2011 11:23:31 +0200 Subject: [PATCH] Change Predis\Commands\Preprocessors to Predis\Command\Processors. --- examples/KeyPrefixes.php | 6 +- .../Preprocessors/ICommandPreprocessor.php | 7 -- .../ICommandPreprocessorChain.php | 11 ---- .../Preprocessors/IPreprocessingSupport.php | 8 --- .../Preprocessors/PreprocessorChain.php | 65 ------------------- .../Commands/Processors/ICommandProcessor.php | 7 ++ .../Processors/ICommandProcessorChain.php | 11 ++++ .../Processors/IProcessingSupport.php | 8 +++ .../KeyPrefixProcessor.php} | 4 +- .../Commands/Processors/ProcessorChain.php | 65 +++++++++++++++++++ lib/Predis/Profiles/ServerProfile.php | 24 +++---- 11 files changed, 108 insertions(+), 108 deletions(-) delete mode 100644 lib/Predis/Commands/Preprocessors/ICommandPreprocessor.php delete mode 100644 lib/Predis/Commands/Preprocessors/ICommandPreprocessorChain.php delete mode 100644 lib/Predis/Commands/Preprocessors/IPreprocessingSupport.php delete mode 100644 lib/Predis/Commands/Preprocessors/PreprocessorChain.php create mode 100644 lib/Predis/Commands/Processors/ICommandProcessor.php create mode 100644 lib/Predis/Commands/Processors/ICommandProcessorChain.php create mode 100644 lib/Predis/Commands/Processors/IProcessingSupport.php rename lib/Predis/Commands/{Preprocessors/KeyPrefixPreprocessor.php => Processors/KeyPrefixProcessor.php} (98%) create mode 100644 lib/Predis/Commands/Processors/ProcessorChain.php diff --git a/examples/KeyPrefixes.php b/examples/KeyPrefixes.php index 9ce94a24..0f5a15a7 100644 --- a/examples/KeyPrefixes.php +++ b/examples/KeyPrefixes.php @@ -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')); diff --git a/lib/Predis/Commands/Preprocessors/ICommandPreprocessor.php b/lib/Predis/Commands/Preprocessors/ICommandPreprocessor.php deleted file mode 100644 index 36bb4311..00000000 --- a/lib/Predis/Commands/Preprocessors/ICommandPreprocessor.php +++ /dev/null @@ -1,7 +0,0 @@ -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]); - } -} diff --git a/lib/Predis/Commands/Processors/ICommandProcessor.php b/lib/Predis/Commands/Processors/ICommandProcessor.php new file mode 100644 index 00000000..db202b41 --- /dev/null +++ b/lib/Predis/Commands/Processors/ICommandProcessor.php @@ -0,0 +1,7 @@ +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]); + } +} diff --git a/lib/Predis/Profiles/ServerProfile.php b/lib/Predis/Profiles/ServerProfile.php index d87db1d0..519708ca 100644 --- a/lib/Predis/Profiles/ServerProfile.php +++ b/lib/Predis/Profiles/ServerProfile.php @@ -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() {