/**
  * Execute a given HTTP request.
  *
  * @param ehough_shortstop_api_HttpRequest $request The HTTP request.
  *
  * @throws ehough_shortstop_api_exception_RuntimeException If something goes wrong.
  *
  * @return ehough_shortstop_api_HttpResponse The HTTP response.
  */
 public final function execute(ehough_shortstop_api_HttpRequest $request)
 {
     /**
      * Fire request event.
      */
     $requestEvent = new ehough_tickertape_GenericEvent($request);
     $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::REQUEST, $requestEvent);
     /**
      * Execute the chain.
      */
     $chainContext = new ehough_chaingang_impl_StandardContext();
     $chainContext->put('request', $request);
     $result = $this->_executionChain->execute($chainContext);
     if (!$result || !$chainContext->containsKey('response') || !$chainContext->get('response') instanceof ehough_shortstop_api_HttpResponse) {
         throw new ehough_shortstop_api_exception_RuntimeException(sprintf('No HTTP transports could execute %s', $request));
     }
     /**
      * Fire response event.
      */
     $response = $chainContext->get('response');
     $responseEvent = new ehough_tickertape_GenericEvent($response, array('request' => $requestEvent->getSubject()));
     $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::RESPONSE, $responseEvent);
     /**
      * All done. Return the response.
      */
     return $response;
 }
 private function _handleTransportException(Exception $e, ehough_shortstop_api_HttpRequest $request, ehough_chaingang_api_Context $context, $isDebugEnabled, ehough_epilog_psr_LoggerInterface $logger)
 {
     $this->_tearDown($request, true);
     /**
      * Fire an error event.
      */
     $transportFailureEvent = new ehough_tickertape_GenericEvent($this, array('request' => $request, 'response' => $context->containsKey('response') ? $context->get('response') : null, 'exception' => $e, 'rethrow' => false, 'tryOtherTransports' => true));
     $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::TRANSPORT_FAILURE, $transportFailureEvent);
     if ($transportFailureEvent->getArgument('rethrow')) {
         if ($isDebugEnabled) {
             $logger->error(sprintf('Caught exception when handling %s (%s). Will re-throw.', $request, $e->getMessage()));
         }
         throw new ehough_shortstop_api_exception_RuntimeException($e->getMessage());
     }
     if ($transportFailureEvent->getArgument('tryOtherTransports')) {
         if ($isDebugEnabled) {
             $logger->debug('Transport failed, but trying the next...');
         }
         return false;
     }
     if ($isDebugEnabled) {
         $logger->debug('Transport failed, and not trying any others...');
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function hasListeners($eventName = null)
 {
     return $this->dispatcher->hasListeners($eventName);
 }