/** * @param Request $request * @return Response * @throws \Exception */ public function send(Request $request) { try { if (!isset($this->currentToken) || $this->currentToken->isExpired()) { $this->currentToken = $this->tokenStorage->findToken($this->consumer); } $this->currentToken->signRequest($request); return $this->getCurlSender()->send($request); } catch (Exception $e) { if ($e instanceof TokenException || $e instanceof CurlException) { if (isset($this->currentToken)) { $this->tokenStorage->markTokenAsBroken($this->currentToken); } $this->currentToken = $this->fetchNewToken(); $this->tokenStorage->saveToken($this->currentToken); $this->currentToken->signRequest($request); return $this->getCurlSender()->send($request); } throw $e; } }
/** * @param Token $token */ public function markTokenAsBroken(Token $token) { unset($this->tokens[$token->getAppId()][$token->getToken()]); }