/**
  * Execute a unit of processing work to be performed.
  *
  * This Command may either complete the required processing and return true,
  * or delegate remaining processing to the next Command in a Chain containing
  * this Command by returning false.
  *
  * @param ehough_chaingang_api_Context $context The Context to be processed by this Command.
  *
  * @return boolean True if the processing of this Context has been completed, or false if the
  *                 processing of this Context should be delegated to a subsequent Command
  *                 in an enclosing Chain.
  */
 public function execute(ehough_chaingang_api_Context $context)
 {
     $response = $context->get('response');
     $encoding = $response->getHeaderValue(ehough_shortstop_api_HttpResponse::HTTP_HEADER_TRANSFER_ENCODING);
     if (strcasecmp($encoding, 'chunked') !== 0) {
         if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
             $this->_logger->debug('Response is not encoded with Chunked-Transfer');
         }
         return false;
     }
     /** @noinspection PhpUndefinedMethodInspection */
     $decoded = self::_decode($response->getEntity()->getContent());
     $context->put('response', $decoded);
     return true;
 }
 /**
  * Execute a unit of processing work to be performed.
  *
  * This Command may either complete the required processing and return true,
  * or delegate remaining processing to the next Command in a Chain containing
  * this Command by returning false.
  *
  * @param ehough_chaingang_api_Context $context The Context to be processed by this Command.
  *
  * @return boolean True if the processing of this Context has been completed, or false if the
  *                 processing of this Context should be delegated to a subsequent Command
  *                 in an enclosing Chain.
  */
 public final function execute(ehough_chaingang_api_Context $context)
 {
     $response = $context->get('response');
     $encoding = $response->getHeaderValue(ehough_shortstop_api_HttpResponse::HTTP_HEADER_CONTENT_ENCODING);
     $logger = $this->getLogger();
     $isDebugEnabled = $logger->isHandling(ehough_epilog_Logger::DEBUG);
     if (strcasecmp($encoding, $this->getExpectedContentEncodingHeaderValue()) !== 0) {
         if ($isDebugEnabled) {
             $logger->debug(sprintf('Content is not encoded with %s', $this->getExpectedContentEncodingHeaderValue()));
         }
         return false;
     }
     if (!$this->isAvailiable()) {
         if ($isDebugEnabled) {
             $logger->debug('Not available on this installation.');
         }
         return false;
     }
     /** @noinspection PhpUndefinedMethodInspection */
     $compressed = $response->getEntity()->getContent();
     if (!is_string($compressed)) {
         $logger->error('Can only decompress string data');
         return false;
     }
     if ($isDebugEnabled) {
         $logger->debug('Attempting to decompress data...');
     }
     /* this will throw an exception if we couldn't decompress it. */
     try {
         $uncompressed = $this->getUncompressed($compressed);
     } catch (Exception $e) {
         return false;
     }
     /* do some logging. */
     if ($isDebugEnabled) {
         $this->_logSuccess($logger, strlen($compressed), strlen($uncompressed));
     }
     $context->put('response', $uncompressed);
     /* signal that we've handled execution. */
     return true;
 }
 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;
 }