Browse Source

Change Predis\Commands\Preprocessors to Predis\Command\Processors.

Daniele Alessandri 14 years ago
parent
commit
09b5d7ac61

+ 3 - 3
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'));

+ 0 - 7
lib/Predis/Commands/Preprocessors/ICommandPreprocessor.php

@@ -1,7 +0,0 @@
-<?php
-
-namespace Predis\Commands\Preprocessors;
-
-interface ICommandPreprocessor {
-    public function process($method, &$arguments);
-}

+ 0 - 11
lib/Predis/Commands/Preprocessors/ICommandPreprocessorChain.php

@@ -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();
-}

+ 0 - 8
lib/Predis/Commands/Preprocessors/IPreprocessingSupport.php

@@ -1,8 +0,0 @@
-<?php
-
-namespace Predis\Commands\Preprocessors;
-
-interface IPreprocessingSupport {
-    public function setPreprocessor(ICommandPreprocessor $processor);
-    public function getPreprocessor();
-}

+ 0 - 65
lib/Predis/Commands/Preprocessors/PreprocessorChain.php

@@ -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]);
-    }
-}

+ 7 - 0
lib/Predis/Commands/Processors/ICommandProcessor.php

@@ -0,0 +1,7 @@
+<?php
+
+namespace Predis\Commands\Processors;
+
+interface ICommandProcessor {
+    public function process($method, &$arguments);
+}

+ 11 - 0
lib/Predis/Commands/Processors/ICommandProcessorChain.php

@@ -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();
+}

+ 8 - 0
lib/Predis/Commands/Processors/IProcessingSupport.php

@@ -0,0 +1,8 @@
+<?php
+
+namespace Predis\Commands\Processors;
+
+interface IProcessingSupport {
+    public function setProcessor(ICommandProcessor $processor);
+    public function getProcessor();
+}

+ 2 - 2
lib/Predis/Commands/Preprocessors/KeyPrefixPreprocessor.php → lib/Predis/Commands/Processors/KeyPrefixProcessor.php

@@ -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;
 

+ 65 - 0
lib/Predis/Commands/Processors/ProcessorChain.php

@@ -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]);
+    }
+}

+ 12 - 12
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() {