12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Predis;
- use Predis\Connection\SingleConnectionInterface;
- abstract class CommunicationException extends PredisException
- {
- private $connection;
-
- public function __construct(
- SingleConnectionInterface $connection, $message = null, $code = null, \Exception $innerException = null
- ) {
- parent::__construct($message, $code, $innerException);
- $this->connection = $connection;
- }
-
- public function getConnection()
- {
- return $this->connection;
- }
-
- public function shouldResetConnection()
- {
- return true;
- }
-
- public static function handle(CommunicationException $exception)
- {
- if ($exception->shouldResetConnection()) {
- $connection = $exception->getConnection();
- if ($connection->isConnected()) {
- $connection->disconnect();
- }
- }
- throw $exception;
- }
- }
|