mirror of
https://github.com/predis/predis.git
synced 2026-08-22 16:41:45 +00:00
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.
This commit is contained in:
@@ -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()`.
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user