CommunicationException.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\SingleConnectionInterface;
  12. /**
  13. * Base exception class for network-related errors.
  14. *
  15. * @author Daniele Alessandri <suppakilla@gmail.com>
  16. */
  17. abstract class CommunicationException extends PredisException
  18. {
  19. private $connection;
  20. /**
  21. * @param SingleConnectionInterface $connection Connection that generated the exception.
  22. * @param string $message Error message.
  23. * @param int $code Error code.
  24. * @param \Exception $innerException Inner exception for wrapping the original error.
  25. */
  26. public function __construct(
  27. SingleConnectionInterface $connection, $message = null, $code = null, \Exception $innerException = null
  28. ) {
  29. parent::__construct($message, $code, $innerException);
  30. $this->connection = $connection;
  31. }
  32. /**
  33. * Gets the connection that generated the exception.
  34. *
  35. * @return SingleConnectionInterface
  36. */
  37. public function getConnection()
  38. {
  39. return $this->connection;
  40. }
  41. /**
  42. * Indicates if the receiver should reset the underlying connection.
  43. *
  44. * @return Boolean
  45. */
  46. public function shouldResetConnection()
  47. {
  48. return true;
  49. }
  50. }