Helpers.php 2.2 KB

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