Просмотр исходного кода

Remove implementation of Predis\Command\Command::__toString().

Issue #151 pointed to a flaw in how command instances were converted
to strings: we were simply truncating their arguments when exceeding
a certain size as this was mostly intended for logging or debugging,
but this approach breaks strings containing multibyte characters so
we decided to drop this feature altogether for the sake of simplicity.

It is still possible to replicate the same (and eventually improved)
behavior externally by fetching ID and arguments of a command out of
a command instance using the public methods made available by the
Predis\Command\CommandInterface.
Daniele Alessandri 11 лет назад
Родитель
Сommit
5c5dd40527
3 измененных файлов с 2 добавлено и 64 удалено
  1. 2 0
      CHANGELOG.md
  2. 0 32
      lib/Predis/Command/Command.php
  3. 0 32
      tests/Predis/Command/CommandTest.php

+ 2 - 0
CHANGELOG.md

@@ -51,6 +51,8 @@ v1.0.0 (201x-xx-xx)
     - `Predis\Command\AbstractCommand` is now `Predis\Command\Command`
     - `Predis\Command\ScriptedCommand` is now `Predis\Command\ScriptCommand`
 
+- Dropped `Predis\Command\Command::__toString()` (see issue #151).
+
 - Renamed `Predis\Connection\ConnectionInterface::writeCommand()` into
   `writeRequest()` for consistency with its counterpart, `readResponse()`.
 

+ 0 - 32
lib/Predis/Command/Command.php

@@ -94,38 +94,6 @@ abstract class Command implements CommandInterface
         return $data;
     }
 
-    /**
-     * Helper function used to reduce a list of arguments to a string.
-     *
-     * @param  string $accumulator Temporary string.
-     * @param  string $argument    Current argument.
-     * @return string
-     */
-    protected function toStringArgumentReducer($accumulator, $argument)
-    {
-        if (strlen($argument) > 32) {
-            $argument = substr($argument, 0, 32) . '[...]';
-        }
-
-        $accumulator .= " $argument";
-
-        return $accumulator;
-    }
-
-    /**
-     * Returns a partial string representation of the command with its arguments.
-     *
-     * @return string
-     */
-    public function __toString()
-    {
-        return array_reduce(
-            $this->getArguments(),
-            array($this, 'toStringArgumentReducer'),
-            $this->getId()
-        );
-    }
-
     /**
      * Normalizes the arguments array passed to a Redis command.
      *

+ 0 - 32
tests/Predis/Command/CommandTest.php

@@ -117,38 +117,6 @@ class CommandTest extends PredisTestCase
         $this->assertNull($command->getHash());
     }
 
-    /**
-     * @group disconnected
-     */
-    public function testToString()
-    {
-        $expected = 'SET key value';
-        $arguments = array('key', 'value');
-
-        $command = $this->getMockForAbstractClass('Predis\Command\Command');
-        $command->expects($this->once())->method('getId')->will($this->returnValue('SET'));
-
-        $command->setRawArguments($arguments);
-
-        $this->assertEquals($expected, (string) $command);
-    }
-
-    /**
-     * @group disconnected
-     */
-    public function testToStringWithLongArguments()
-    {
-        $expected = 'SET key abcdefghijklmnopqrstuvwxyz012345[...]';
-        $arguments = array('key', 'abcdefghijklmnopqrstuvwxyz0123456789');
-
-        $command = $this->getMockForAbstractClass('Predis\Command\Command');
-        $command->expects($this->once())->method('getId')->will($this->returnValue('SET'));
-
-        $command->setRawArguments($arguments);
-
-        $this->assertEquals($expected, (string) $command);
-    }
-
     /**
      * @group disconnected
      */