Пример #1
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));
     }
 }
Пример #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());
     }
 }