PrefixHelpers.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Commands;
  11. /**
  12. * Class that defines a few helpers method for prefixing keys.
  13. *
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. */
  16. class PrefixHelpers
  17. {
  18. /**
  19. * Applies the specified prefix to all the arguments.
  20. *
  21. * @param array $arguments Array of arguments.
  22. * @param string $prefix The prefix string.
  23. * @return array
  24. */
  25. public static function multipleKeys(Array $arguments, $prefix)
  26. {
  27. foreach ($arguments as &$key) {
  28. $key = "$prefix$key";
  29. }
  30. return $arguments;
  31. }
  32. /**
  33. * Applies the specified prefix to all the arguments but the last one.
  34. *
  35. * @param array $arguments Array of arguments.
  36. * @param string $prefix The prefix string.
  37. * @return array
  38. */
  39. public static function skipLastArgument(Array $arguments, $prefix)
  40. {
  41. $length = count($arguments);
  42. for ($i = 0; $i < $length - 1; $i++) {
  43. $arguments[$i] = "$prefix{$arguments[$i]}";
  44. }
  45. return $arguments;
  46. }
  47. }