Beispiel #1
0
 /**
  * Sends internal requests.
  *
  * @param array $internalRequests The internal requests.
  *
  * @throws \Ivory\HttpAdapter\MultiHttpAdapterException If an error occurred.
  *
  * @return array The responses.
  */
 private function sendInternalRequests(array $internalRequests)
 {
     if (!empty($internalRequests) && $this->configuration->hasEventDispatcher()) {
         $this->configuration->getEventDispatcher()->dispatch(Events::MULTI_PRE_SEND, $multiPreSendEvent = new MultiPreSendEvent($this, $internalRequests));
         $internalRequests = $multiPreSendEvent->getRequests();
     }
     $responses = array();
     $exceptions = array();
     $successHandler = function (ResponseInterface $response) use(&$responses) {
         $responses[] = $response;
     };
     $errorHandler = function (HttpAdapterException $exception) use(&$exceptions) {
         $exceptions[] = $exception;
     };
     $this->doSendInternalRequests($internalRequests, $successHandler, $errorHandler);
     if (!empty($responses) && $this->configuration->hasEventDispatcher()) {
         $this->configuration->getEventDispatcher()->dispatch(Events::MULTI_POST_SEND, $postSendEvent = new MultiPostSendEvent($this, $responses));
         $exceptions = array_merge($exceptions, $postSendEvent->getExceptions());
         $responses = $postSendEvent->getResponses();
     }
     if (!empty($exceptions)) {
         if ($this->configuration->hasEventDispatcher()) {
             $this->configuration->getEventDispatcher()->dispatch(Events::MULTI_EXCEPTION, $exceptionEvent = new MultiExceptionEvent($this, $exceptions));
             $responses = array_merge($responses, $exceptionEvent->getResponses());
             $exceptions = $exceptionEvent->getExceptions();
         }
         if (!empty($exceptions)) {
             throw new MultiHttpAdapterException($exceptions, $responses);
         }
     }
     return $responses;
 }
Beispiel #2
0
 /**
  * @param Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
  * @param Ivory\HttpAdapter\ConfigurationInterface                   $configuration
  * @param Ivory\HttpAdapter\HttpAdapterInterface                     $adapter
  */
 function let($eventDispatcher, $configuration, $adapter)
 {
     $configuration->setTimeout(Yo::TIMEOUT)->shouldBeCalled();
     $configuration->setUserAgent(Yo::USER_AGENT)->shouldBeCalled();
     $configuration->setEncodingType(ConfigurationInterface::ENCODING_TYPE_URLENCODED)->shouldBeCalled();
     $configuration->getEventDispatcher()->willReturn($eventDispatcher);
     $adapter->getConfiguration()->willReturn($configuration);
     $adapter->setConfiguration($configuration)->shouldBeCalled();
     $this->beConstructedWith($adapter, self::API_KEY);
 }