|
@@ -18,36 +18,70 @@ namespace Predis\Commands;
|
|
|
*/
|
|
|
class PrefixHelpers
|
|
|
{
|
|
|
+ /**
|
|
|
+ * Applies the specified prefix only the first argument.
|
|
|
+ *
|
|
|
+ * @param ICommand $command Command instance.
|
|
|
+ * @param string $prefix Prefix string.
|
|
|
+ */
|
|
|
+ protected function first(ICommand $command, $prefix) {
|
|
|
+ $arguments = $command->getArguments();
|
|
|
+
|
|
|
+ $arguments[0] = "$prefix{$arguments[0]}";
|
|
|
+
|
|
|
+ $command->setRawArguments($arguments);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Applies the specified prefix to all the arguments.
|
|
|
*
|
|
|
- * @param array $arguments Array of arguments.
|
|
|
- * @param string $prefix The prefix string.
|
|
|
- * @return array
|
|
|
+ * @param ICommand $command Command instance.
|
|
|
+ * @param string $prefix Prefix string.
|
|
|
*/
|
|
|
- public static function multipleKeys(Array $arguments, $prefix)
|
|
|
+ public static function all(ICommand $command, $prefix)
|
|
|
{
|
|
|
+ $arguments = $command->getArguments();
|
|
|
+
|
|
|
foreach ($arguments as &$key) {
|
|
|
$key = "$prefix$key";
|
|
|
}
|
|
|
|
|
|
- return $arguments;
|
|
|
+ $command->setRawArguments($arguments);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Applies the specified prefix only to even arguments in the list.
|
|
|
+ *
|
|
|
+ * @param ICommand $command Command instance.
|
|
|
+ * @param string $prefix Prefix string.
|
|
|
+ */
|
|
|
+ public static function interleaved(ICommand $command, $prefix)
|
|
|
+ {
|
|
|
+ $arguments = $command->getArguments();
|
|
|
+ $length = count($arguments);
|
|
|
+
|
|
|
+ for ($i = 0; $i < $length; $i += 2) {
|
|
|
+ $arguments[$i] = "$prefix{$arguments[$i]}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $command->setRawArguments($arguments);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Applies the specified prefix to all the arguments but the last one.
|
|
|
*
|
|
|
- * @param array $arguments Array of arguments.
|
|
|
- * @param string $prefix The prefix string.
|
|
|
- * @return array
|
|
|
+ * @param ICommand $command Command instance.
|
|
|
+ * @param string $prefix Prefix string.
|
|
|
*/
|
|
|
- public static function skipLastArgument(Array $arguments, $prefix)
|
|
|
+ public static function skipLast(ICommand $command, $prefix)
|
|
|
{
|
|
|
+ $arguments = $command->getArguments();
|
|
|
$length = count($arguments);
|
|
|
+
|
|
|
for ($i = 0; $i < $length - 1; $i++) {
|
|
|
$arguments[$i] = "$prefix{$arguments[$i]}";
|
|
|
}
|
|
|
|
|
|
- return $arguments;
|
|
|
+ $command->setRawArguments($arguments);
|
|
|
}
|
|
|
}
|