ServerInfoV26x.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/info
  13. *
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. */
  16. class ServerInfoV26x extends ServerInfo
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function parseResponse($data)
  22. {
  23. if ($data === '') {
  24. return array();
  25. }
  26. $info = array();
  27. $current = null;
  28. $infoLines = preg_split('/\r?\n/', $data);
  29. if (isset($infoLines[0]) && $infoLines[0][0] !== '#') {
  30. return parent::parseResponse($data);
  31. }
  32. foreach ($infoLines as $row) {
  33. if ($row === '') {
  34. continue;
  35. }
  36. if (preg_match('/^# (\w+)$/', $row, $matches)) {
  37. $info[$matches[1]] = array();
  38. $current = &$info[$matches[1]];
  39. continue;
  40. }
  41. list($k, $v) = $this->parseRow($row);
  42. $current[$k] = $v;
  43. }
  44. return $info;
  45. }
  46. }