Browse Source

Implement Predis\Command::__toString().

Daniele Alessandri 14 years ago
parent
commit
798e2b18dc
1 changed files with 12 additions and 0 deletions
  1. 12 0
      lib/Predis.php

+ 12 - 0
lib/Predis.php

@@ -488,6 +488,18 @@ abstract class Command {
     public final function __invoke() {
     public final function __invoke() {
         return $this->serializeRequest($this->getCommandId(), $this->getArguments());
         return $this->serializeRequest($this->getCommandId(), $this->getArguments());
     }
     }
+
+    private static function reduceArguments($str, $arg) {
+        if (strlen($arg) > 32) {
+            $arg = substr($arg, 0, 32) . '[...]';
+        }
+        $str .= " $arg";
+        return $str;
+    }
+
+    public function __toString() {
+        return array_reduce($this->getArguments(), 'self::reduceArguments', $this->getCommandId());
+    }
 }
 }
 
 
 abstract class InlineCommand extends Command {
 abstract class InlineCommand extends Command {