ZSetUnionStore.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Predis\Commands;
  3. class ZSetUnionStore extends Command {
  4. public function getId() {
  5. return 'ZUNIONSTORE';
  6. }
  7. public function filterArguments(Array $arguments) {
  8. $options = array();
  9. $argc = count($arguments);
  10. if ($argc > 2 && is_array($arguments[$argc - 1])) {
  11. $options = $this->prepareOptions(array_pop($arguments));
  12. }
  13. if (is_array($arguments[1])) {
  14. $arguments = array_merge(
  15. array($arguments[0], count($arguments[1])),
  16. $arguments[1]
  17. );
  18. }
  19. return array_merge($arguments, $options);
  20. }
  21. private function prepareOptions($options) {
  22. $opts = array_change_key_case($options, CASE_UPPER);
  23. $finalizedOpts = array();
  24. if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) {
  25. $finalizedOpts[] = 'WEIGHTS';
  26. foreach ($opts['WEIGHTS'] as $weight) {
  27. $finalizedOpts[] = $weight;
  28. }
  29. }
  30. if (isset($opts['AGGREGATE'])) {
  31. $finalizedOpts[] = 'AGGREGATE';
  32. $finalizedOpts[] = $opts['AGGREGATE'];
  33. }
  34. return $finalizedOpts;
  35. }
  36. protected function canBeHashed() {
  37. $args = $this->getArguments();
  38. return $this->checkSameHashForKeys(
  39. array_merge(array($args[0]), array_slice($args, 2, $args[1]))
  40. );
  41. }
  42. }