/**
  * {@inheritdoc}
  */
 protected function doSendInternalRequests(array $internalRequests)
 {
     if (!empty($internalRequests)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_CREATED, $multiRequestCreatedEvent = new MultiRequestCreatedEvent($this, $internalRequests));
         $internalRequests = $multiRequestCreatedEvent->getRequests();
     }
     $exceptions = array();
     try {
         $responses = parent::doSendInternalRequests($internalRequests);
     } catch (MultiHttpAdapterException $e) {
         $responses = $e->getResponses();
         $exceptions = $e->getExceptions();
     }
     if (!empty($responses)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_SENT, $requestSentEvent = new MultiRequestSentEvent($this, $responses));
         $exceptions = array_merge($exceptions, $requestSentEvent->getExceptions());
         $responses = $requestSentEvent->getResponses();
     }
     if (!empty($exceptions)) {
         $this->eventDispatcher->dispatch(Events::MULTI_REQUEST_ERRORED, $exceptionEvent = new MultiRequestErroredEvent($this, $exceptions));
         $responses = array_merge($responses, $exceptionEvent->getResponses());
         $exceptions = $exceptionEvent->getExceptions();
         if (!empty($exceptions)) {
             throw new MultiHttpAdapterException($exceptions, $responses);
         }
     }
     return $responses;
 }
Пример #2
0
 /**
  * On multi request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestSentEvent $event The multi request sent event.
  */
 public function onMultiRequestSent(MultiRequestSentEvent $event)
 {
     $redirectRequests = array();
     foreach ($event->getResponses() as $response) {
         try {
             $redirectRequest = $this->redirect->createRedirectRequest($response, $response->getParameter('request'), $event->getHttpAdapter());
         } catch (HttpAdapterException $e) {
             $event->removeResponse($response);
             $event->addException($e);
             continue;
         }
         if ($redirectRequest === false) {
             $event->removeResponse($response);
             $event->addResponse($this->redirect->prepareResponse($response, $response->getParameter('request')));
         } else {
             $redirectRequests[] = $redirectRequest;
             $event->removeResponse($response);
         }
     }
     if (empty($redirectRequests)) {
         return;
     }
     try {
         $event->addResponses($event->getHttpAdapter()->sendRequests($redirectRequests));
     } catch (MultiHttpAdapterException $e) {
         $event->addResponses($e->getResponses());
         $event->addExceptions($e->getExceptions());
     }
 }
 /**
  * On multi request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestSentEvent $event The multi request sent event.
  */
 public function onMultiRequestSent(MultiRequestSentEvent $event)
 {
     foreach ($event->getResponses() as $response) {
         if (!$this->statusCode->validate($response)) {
             $event->addException($this->createStatusCodeException($response, $response->getParameter('request'), $event->getHttpAdapter()));
             $event->removeResponse($response);
         }
     }
 }
Пример #4
0
 /**
  * On multi request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestSentEvent $event The multi request sent event.
  */
 public function onMultiRequestSent(MultiRequestSentEvent $event)
 {
     foreach ($event->getResponses() as $response) {
         $this->cookieJar->extract($response->getParameter('request'), $response);
     }
 }
Пример #5
0
 /**
  * On multi request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestSentEvent $event The multi request sent event.
  */
 public function onMultiRequestSent(MultiRequestSentEvent $event)
 {
     foreach ($event->getResponses() as $response) {
         $request = $this->debug($event->getHttpAdapter(), $response->getParameter('request'), $response);
         $event->removeResponse($response);
         $event->addResponse($response->withParameter('request', $request));
     }
 }
Пример #6
0
 /**
  * On multi request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\MultiRequestSentEvent $event The multi request sent event.
  */
 public function onMultiRequestSent(MultiRequestSentEvent $event)
 {
     foreach ($event->getResponses() as $response) {
         $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $response->getParameter('request')));
     }
 }