PubSubPubsub.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Command;
  11. /**
  12. * @link http://redis.io/commands/pubsub
  13. *
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. */
  16. class PubSubPubsub extends Command
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function getId()
  22. {
  23. return 'PUBSUB';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function parseResponse($data)
  29. {
  30. switch (strtolower($this->getArgument(0))) {
  31. case 'numsub':
  32. return self::processNumsub($data);
  33. default:
  34. return $data;
  35. }
  36. }
  37. /**
  38. * Returns the processed response to PUBSUB NUMSUB.
  39. *
  40. * @param array $channels List of channels
  41. *
  42. * @return array
  43. */
  44. protected static function processNumsub(array $channels)
  45. {
  46. $processed = array();
  47. $count = count($channels);
  48. for ($i = 0; $i < $count; ++$i) {
  49. $processed[$channels[$i]] = $channels[++$i];
  50. }
  51. return $processed;
  52. }
  53. }