123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace Predis\Command;
- class ZSetRange extends PrefixableCommand
- {
-
- public function getId()
- {
- return 'ZRANGE';
- }
-
- protected function filterArguments(Array $arguments)
- {
- if (count($arguments) === 4) {
- $lastType = gettype($arguments[3]);
- if ($lastType === 'string' && strtoupper($arguments[3]) === 'WITHSCORES') {
-
- $arguments[3] = array('WITHSCORES' => true);
- $lastType = 'array';
- }
- if ($lastType === 'array') {
- $options = $this->prepareOptions(array_pop($arguments));
- return array_merge($arguments, $options);
- }
- }
- return $arguments;
- }
-
- protected function prepareOptions($options)
- {
- $opts = array_change_key_case($options, CASE_UPPER);
- $finalizedOpts = array();
- if (!empty($opts['WITHSCORES'])) {
- $finalizedOpts[] = 'WITHSCORES';
- }
- return $finalizedOpts;
- }
-
- protected function withScores()
- {
- $arguments = $this->getArguments();
- if (count($arguments) < 4) {
- return false;
- }
- return strtoupper($arguments[3]) === 'WITHSCORES';
- }
-
- public function parseResponse($data)
- {
- if ($this->withScores()) {
- $result = array();
- for ($i = 0; $i < count($data); $i++) {
- $result[] = array($data[$i], $data[++$i]);
- }
- return $result;
- }
- return $data;
- }
- }
|