/**
  * {@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;
 }
Ejemplo n.º 2
0
 /**
  * On pre send event.
  *
  * @param \Ivory\HttpAdapter\Event\PreSendEvent $event The pre send event.
  */
 public function onPreSend(PreSendEvent $event)
 {
     $event->setRequest($this->getTimer()->start($event->getRequest()));
 }
Ejemplo n.º 3
0
 /**
  * On pre send event.
  *
  * @param \Ivory\HttpAdapter\Event\PreSendEvent $event The event.
  */
 public function onPreSend(PreSendEvent $event)
 {
     $this->stopwatch->start($this->getStopwatchName($event->getHttpAdapter(), $event->getRequest()));
 }
Ejemplo n.º 4
0
 /**
  * On pre send event.
  *
  * @param \Ivory\HttpAdapter\Event\PreSendEvent $event The pre send event.
  */
 public function onPreSend(PreSendEvent $event)
 {
     $this->cookieJar->populate($event->getRequest());
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * On pre send event.
  *
  * @param \Ivory\HttpAdapter\Event\PreSendEvent $event The pre send event.
  */
 public function onPreSend(PreSendEvent $event)
 {
     $this->basicAuth->authenticate($event->getRequest());
 }
Ejemplo n.º 7
0
 /**
  * Creates a post send event.
  *
  * @param \Ivory\HttpAdapter\HttpAdapterInterface             $httpAdapter The http adapter.
  * @param \Ivory\HttpAdapter\Message\InternalRequestInterface $request     The request.
  * @param \Ivory\HttpAdapter\Message\ResponseInterface        $response    The response.
  */
 public function __construct(HttpAdapterInterface $httpAdapter, InternalRequestInterface $request, ResponseInterface $response)
 {
     parent::__construct($httpAdapter, $request);
     $this->setResponse($response);
 }