Helpers.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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;
  11. /**
  12. * Defines a few helper methods.
  13. *
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. * @deprecated Deprecated since v0.8.3.
  16. */
  17. class Helpers
  18. {
  19. /**
  20. * Offers a generic and reusable method to handle exceptions generated by
  21. * a connection object.
  22. *
  23. * @deprecated Deprecated since v0.8.3 - moved in Predis\CommunicationException::handle()
  24. * @param CommunicationException $exception Exception.
  25. */
  26. public static function onCommunicationException(CommunicationException $exception)
  27. {
  28. if ($exception->shouldResetConnection()) {
  29. $connection = $exception->getConnection();
  30. if ($connection->isConnected()) {
  31. $connection->disconnect();
  32. }
  33. }
  34. throw $exception;
  35. }
  36. /**
  37. * Normalizes the arguments array passed to a Redis command.
  38. *
  39. * @deprecated Deprecated since v0.8.3 - moved in Predis\Command\AbstractCommand::normalizeArguments()
  40. * @param array $arguments Arguments for a command.
  41. * @return array
  42. */
  43. public static function filterArrayArguments(Array $arguments)
  44. {
  45. if (count($arguments) === 1 && is_array($arguments[0])) {
  46. return $arguments[0];
  47. }
  48. return $arguments;
  49. }
  50. /**
  51. * Normalizes the arguments array passed to a variadic Redis command.
  52. *
  53. * @deprecated Deprecated since v0.8.3 - moved in Predis\Command\AbstractCommand::normalizeVariadic()
  54. * @param array $arguments Arguments for a command.
  55. * @return array
  56. */
  57. public static function filterVariadicValues(Array $arguments)
  58. {
  59. if (count($arguments) === 2 && is_array($arguments[1])) {
  60. return array_merge(array($arguments[0]), $arguments[1]);
  61. }
  62. return $arguments;
  63. }
  64. }