Helpers.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Predis;
  3. use Predis\Network\IConnection;
  4. use Predis\Network\IConnectionCluster;
  5. class Helpers {
  6. public static function isCluster(IConnection $connection) {
  7. return $connection instanceof IConnectionCluster;
  8. }
  9. public static function onCommunicationException(CommunicationException $exception) {
  10. if ($exception->shouldResetConnection()) {
  11. $connection = $exception->getConnection();
  12. if ($connection->isConnected()) {
  13. $connection->disconnect();
  14. }
  15. }
  16. throw $exception;
  17. }
  18. public static function filterArrayArguments(Array $arguments) {
  19. if (count($arguments) === 1 && is_array($arguments[0])) {
  20. return $arguments[0];
  21. }
  22. return $arguments;
  23. }
  24. public static function filterVariadicValues(Array $arguments) {
  25. if (count($arguments) === 2 && is_array($arguments[1])) {
  26. return array_merge(array($arguments[0]), $arguments[1]);
  27. }
  28. return $arguments;
  29. }
  30. public static function getKeyHashablePart($key) {
  31. $start = strpos($key, '{');
  32. if ($start !== false) {
  33. $end = strpos($key, '}', $start);
  34. if ($end !== false) {
  35. $key = substr($key, ++$start, $end - $start);
  36. }
  37. }
  38. return $key;
  39. }
  40. }