ZSetUnionStore.php 1.2 KB

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