/**
  * {@inheritdoc}
  */
 protected function sendInternalRequest(InternalRequestInterface $internalRequest)
 {
     try {
         $this->eventDispatcher->dispatch(Events::PRE_SEND, $preSendEvent = new PreSendEvent($this, $internalRequest));
         $response = parent::sendInternalRequest($preSendEvent->getRequest());
         $this->eventDispatcher->dispatch(Events::POST_SEND, $postSendEvent = new PostSendEvent($this, $preSendEvent->getRequest(), $response));
         if ($postSendEvent->hasException()) {
             throw $postSendEvent->getException();
         }
         $response = $postSendEvent->getResponse();
     } catch (HttpAdapterException $e) {
         $e->setRequest($internalRequest);
         $e->setResponse(isset($response) ? $response : null);
         $this->eventDispatcher->dispatch(Events::EXCEPTION, $exceptionEvent = new ExceptionEvent($this, $e));
         if ($exceptionEvent->hasResponse()) {
             return $exceptionEvent->getResponse();
         }
         throw $exceptionEvent->getException();
     }
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Sends an internal request.
  *
  * @param \Ivory\HttpAdapter\Message\InternalRequestInterface $internalRequest The internal request.
  *
  * @throws \Ivory\HttpAdapter\HttpAdapterException If an error occurred.
  *
  * @return \Ivory\HttpAdapter\Message\ResponseInterface The response.
  */
 private function sendInternalRequest(InternalRequestInterface $internalRequest)
 {
     try {
         if ($this->configuration->hasEventDispatcher()) {
             $this->configuration->getEventDispatcher()->dispatch(Events::PRE_SEND, $preSendEvent = new PreSendEvent($this, $internalRequest));
             $internalRequest = $preSendEvent->getRequest();
         }
         $response = $this->doSendInternalRequest($internalRequest);
         if ($this->configuration->hasEventDispatcher()) {
             $this->configuration->getEventDispatcher()->dispatch(Events::POST_SEND, $postSendEvent = new PostSendEvent($this, $preSendEvent->getRequest(), $response));
             if ($postSendEvent->hasException()) {
                 throw $postSendEvent->getException();
             }
             $response = $postSendEvent->getResponse();
         }
     } catch (HttpAdapterException $e) {
         $e->setRequest($internalRequest);
         $e->setResponse(isset($response) ? $response : null);
         if ($this->configuration->hasEventDispatcher()) {
             $this->configuration->getEventDispatcher()->dispatch(Events::EXCEPTION, $exceptionEvent = new ExceptionEvent($this, $e));
             if ($exceptionEvent->hasResponse()) {
                 return $exceptionEvent->getResponse();
             }
             $e = $exceptionEvent->getException();
         }
         throw $e;
     }
     return $response;
 }