Преглед на файлове

Rework classes and interfaces in Predis\Command\Processor namespace.

  - Renamed `Predis\Command\Processor\CommandProcessorInterface`
  - Removed `Predis\Command\Processor\CommandProcessorChainInterface`
Daniele Alessandri преди 11 години
родител
ревизия
5529e33047

+ 4 - 0
CHANGELOG.md

@@ -82,6 +82,10 @@ v0.9.0 (201x-xx-xx)
   they can also define the needed logic in their command classes by implementing
   `Predis\Command\PrefixableCommandInterface` just like before.
 
+- Renamed interface `Predis\Command\Processor\CommandProcessorInterface` to a
+  shorter `Predis\Command\Processor\ProcessorInterface`. Also removed interface
+  for chain processors since it is basically useless.
+
 - The client can now send raw commands using `Predis\Client::executeRaw()`.
 
 

+ 0 - 46
lib/Predis/Command/Processor/CommandProcessorChainInterface.php

@@ -1,46 +0,0 @@
-<?php
-
-/*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Predis\Command\Processor;
-
-use IteratorAggregate;
-use Countable;
-
-/**
- * A command processor chain processes a command using multiple chained command
- * processor before it is sent to Redis.
- *
- * @author Daniele Alessandri <suppakilla@gmail.com>
- */
-interface CommandProcessorChainInterface
-    extends CommandProcessorInterface, IteratorAggregate, Countable
-{
-    /**
-     * Adds the given command processor.
-     *
-     * @param CommandProcessorInterface $processor Command processor.
-     */
-    public function add(CommandProcessorInterface $processor);
-
-    /**
-     * Removes the given command processor from the chain if previously added.
-     *
-     * @param CommandProcessorInterface $processor Command processor.
-     */
-    public function remove(CommandProcessorInterface $processor);
-
-    /**
-     * Returns an ordered list of the command processors in the chain.
-     *
-     * @return array
-     */
-    public function getProcessors();
-}

+ 4 - 3
lib/Predis/Command/Processor/KeyPrefixProcessor.php

@@ -11,16 +11,17 @@
 
 namespace Predis\Command\Processor;
 
+use InvalidArgumentException;
 use Predis\Command\CommandInterface;
 use Predis\Command\PrefixableCommandInterface;
 
 /**
- * Command processor used to prefix the keys contained in the arguments of a
- * Redis command.
+ * Command processor capable of prefixing keys stored in the arguments of Redis
+ * commands supported.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class KeyPrefixProcessor implements CommandProcessorInterface
+class KeyPrefixProcessor implements ProcessorInterface
 {
     private $prefix;
     private $commands;

+ 12 - 9
lib/Predis/Command/Processor/ProcessorChain.php

@@ -11,6 +11,9 @@
 
 namespace Predis\Command\Processor;
 
+use ArrayAccess;
+use ArrayIterator;
+use InvalidArgumentException;
 use Predis\Command\CommandInterface;
 
 /**
@@ -18,12 +21,12 @@ use Predis\Command\CommandInterface;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
+class ProcessorChain implements ArrayAccess, ProcessorInterface
 {
     private $processors = array();
 
     /**
-     * @param array $processors List of instances of CommandProcessorInterface.
+     * @param array $processors List of instances of ProcessorInterface.
      */
     public function __construct($processors = array())
     {
@@ -35,7 +38,7 @@ class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
     /**
      * {@inheritdoc}
      */
-    public function add(CommandProcessorInterface $processor)
+    public function add(ProcessorInterface $processor)
     {
         $this->processors[] = $processor;
     }
@@ -43,7 +46,7 @@ class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
     /**
      * {@inheritdoc}
      */
-    public function remove(CommandProcessorInterface $processor)
+    public function remove(ProcessorInterface $processor)
     {
         if (false !== $index = array_search($processor, $this->processors, true)) {
             unset($this[$index]);
@@ -71,11 +74,11 @@ class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
     /**
      * Returns an iterator over the list of command processor in the chain.
      *
-     * @return \ArrayIterator
+     * @return ArrayIterator
      */
     public function getIterator()
     {
-        return new \ArrayIterator($this->processors);
+        return new ArrayIterator($this->processors);
     }
 
     /**
@@ -109,10 +112,10 @@ class ProcessorChain implements CommandProcessorChainInterface, \ArrayAccess
      */
     public function offsetSet($index, $processor)
     {
-        if (!$processor instanceof CommandProcessorInterface) {
-            throw new \InvalidArgumentException(
+        if (!$processor instanceof ProcessorInterface) {
+            throw new InvalidArgumentException(
                 "A processor chain accepts only instances of ".
-                "'Predis\Command\Processor\CommandProcessorInterface'."
+                "'Predis\Command\Processor\ProcessorInterface'."
             );
         }
 

+ 2 - 2
lib/Predis/Command/Processor/CommandProcessorInterface.php → lib/Predis/Command/Processor/ProcessorInterface.php

@@ -14,11 +14,11 @@ namespace Predis\Command\Processor;
 use Predis\Command\CommandInterface;
 
 /**
- * Command processor process Redis commands before they are sent to Redis.
+ * A command processor processes Redis commands before they are sent to Redis.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-interface CommandProcessorInterface
+interface ProcessorInterface
 {
     /**
      * Processes the given Redis command.

+ 2 - 2
lib/Predis/Configuration/PrefixOption.php

@@ -12,7 +12,7 @@
 namespace Predis\Configuration;
 
 use Predis\Command\Processor\KeyPrefixProcessor;
-use Predis\Command\Processor\CommandProcessorInterface;
+use Predis\Command\Processor\ProcessorInterface;
 
 /**
  * Configures a command processor that apply the specified prefix string to a
@@ -27,7 +27,7 @@ class PrefixOption implements OptionInterface
      */
     public function filter(OptionsInterface $options, $value)
     {
-        if ($value instanceof CommandProcessorInterface) {
+        if ($value instanceof ProcessorInterface) {
             return $value;
         }
 

+ 2 - 2
lib/Predis/Profile/RedisProfile.php

@@ -14,7 +14,7 @@ namespace Predis\Profile;
 use InvalidArgumentException;
 use ReflectionClass;
 use Predis\ClientException;
-use Predis\Command\Processor\CommandProcessorInterface;
+use Predis\Command\Processor\ProcessorInterface;
 
 /**
  * Base class implementing common functionalities for Redis server profiles.
@@ -120,7 +120,7 @@ abstract class RedisProfile implements ProfileInterface
     /**
      * {@inheritdoc}
      */
-    public function setProcessor(CommandProcessorInterface $processor = null)
+    public function setProcessor(ProcessorInterface $processor = null)
     {
         $this->processor = $processor;
     }

+ 4 - 4
tests/PHPUnit/PredisProfileTestCase.php

@@ -211,7 +211,7 @@ abstract class PredisProfileTestCase extends PredisTestCase
      */
     public function testSetProcessor()
     {
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
 
         $profile = $this->getProfile();
         $profile->setProcessor($processor);
@@ -224,7 +224,7 @@ abstract class PredisProfileTestCase extends PredisTestCase
      */
     public function testSetAndUnsetProcessor()
     {
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $profile = $this->getProfile();
 
         $profile->setProcessor($processor);
@@ -243,7 +243,7 @@ abstract class PredisProfileTestCase extends PredisTestCase
     {
         $argsRef = null;
 
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $processor->expects($this->once())
                   ->method('process')
                   ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
@@ -263,7 +263,7 @@ abstract class PredisProfileTestCase extends PredisTestCase
      */
     public function testChainOfProcessors()
     {
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $processor->expects($this->exactly(2))
                   ->method('process');
 

+ 1 - 1
tests/Predis/Command/Processor/KeyPrefixProcessorTest.php

@@ -28,7 +28,7 @@ class KeyPrefixProcessorTest extends PredisTestCase
         $prefix = 'prefix:';
         $processor = new KeyPrefixProcessor($prefix);
 
-        $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $processor);
+        $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $processor);
         $this->assertEquals($prefix, $processor->getPrefix());
     }
 

+ 19 - 20
tests/Predis/Command/Processor/ProcessorChainTest.php

@@ -25,8 +25,7 @@ class ProcessorChainTest extends PredisTestCase
     {
         $chain = new ProcessorChain();
 
-        $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $chain);
-        $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorChainInterface', $chain);
+        $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $chain);
         $this->assertEmpty($chain->getProcessors());
     }
 
@@ -36,8 +35,8 @@ class ProcessorChainTest extends PredisTestCase
     public function testConstructorWithProcessorsArray()
     {
         $processors = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain($processors);
@@ -51,8 +50,8 @@ class ProcessorChainTest extends PredisTestCase
     public function testCountProcessors()
     {
         $processors = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain($processors);
@@ -66,8 +65,8 @@ class ProcessorChainTest extends PredisTestCase
     public function testAddProcessors()
     {
         $processors = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain();
@@ -83,13 +82,13 @@ class ProcessorChainTest extends PredisTestCase
     public function testAddMoreProcessors()
     {
         $processors1 = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $processors2 = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain($processors1);
@@ -105,8 +104,8 @@ class ProcessorChainTest extends PredisTestCase
     public function testRemoveProcessors()
     {
         $processors = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain($processors);
@@ -123,10 +122,10 @@ class ProcessorChainTest extends PredisTestCase
      */
     public function testRemoveProcessorNotInChain()
     {
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $processors = array(
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
-            $this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
+            $this->getMock('Predis\Command\Processor\ProcessorInterface'),
         );
 
         $chain = new ProcessorChain($processors);
@@ -140,7 +139,7 @@ class ProcessorChainTest extends PredisTestCase
      */
     public function testRemoveProcessorFromEmptyChain()
     {
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
 
         $chain = new ProcessorChain();
         $this->assertEmpty($chain->getProcessors());
@@ -156,10 +155,10 @@ class ProcessorChainTest extends PredisTestCase
     {
         $command = $this->getMock('Predis\Command\CommandInterface');
 
-        $processor1 = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor1 = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $processor1->expects($this->once())->method('process')->with($command);
 
-        $processor2 = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor2 = $this->getMock('Predis\Command\Processor\ProcessorInterface');
         $processor2->expects($this->once())->method('process')->with($command);
 
         $processors = array($processor1, $processor2);

+ 1 - 1
tests/Predis/Configuration/OptionsTest.php

@@ -51,7 +51,7 @@ class OptionsTest extends PredisTestCase
 
         $this->assertInternalType('bool', $options->exceptions);
         $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile);
-        $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $options->prefix);
+        $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $options->prefix);
         $this->assertInstanceOf('Predis\Connection\FactoryInterface', $options->connections);
         $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster);
         $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $options->replication);

+ 2 - 2
tests/Predis/Configuration/PrefixOptionTest.php

@@ -39,7 +39,7 @@ class PrefixOptionTest extends PredisTestCase
 
         $return = $option->filter($options, $value = 'prefix:');
 
-        $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $return);
+        $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $return);
         $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $return);
         $this->assertSame($value, $return->getPrefix());
     }
@@ -51,7 +51,7 @@ class PrefixOptionTest extends PredisTestCase
     {
         $option = new PrefixOption();
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
 
         $return = $option->filter($options, $processor);