You are here

class MiddlewareFactory in Lockr 7.3

Hierarchy

Expanded class hierarchy of MiddlewareFactory

File

vendor/lockr/lockr/src/Guzzle/MiddlewareFactory.php, line 10

Namespace

Lockr\Guzzle
View source
class MiddlewareFactory {

  /**
   * @return callable
   */
  public static function retry() {
    return GuzzleHttp\Middleware::retry(self::retryDecider(), self::retryDelay());
  }

  /**
   * @return callable
   */
  private static function retryDelay() {
    return function ($retries) {
      return 1000 * $retries + mt_rand(0, 300);
    };
  }

  /**
   * @return callable
   */
  private static function retryDecider() {
    return function ($retries, RequestInterface $req, ResponseInterface $resp = null, RequestException $ex = null) {
      if ($retries >= 5) {
        return false;
      }
      if ($ex instanceof ConnectException) {
        return true;
      }
      if ($resp) {
        if ($resp
          ->getStatusCode() >= 500) {
          return true;
        }
      }
      return false;
    };
  }

}

Members