/** * 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; }
/** * 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. * * @throws ehough_shortstop_api_exception_RuntimeException If something goes wrong. * * @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) { /* this will never be null if the parent chain does its job */ $request = $context->get('request'); $logger = $this->getLogger(); $isDebugEnabled = $logger->isHandling(ehough_epilog_Logger::DEBUG); if ($isDebugEnabled) { $logger->debug(sprintf('Seeing if able to handle %s', $request)); } if ($this->isAvailable() === false || $this->canHandle($request) === false) { if ($isDebugEnabled) { $logger->debug(sprintf('Unavailable or declined to handle %s', $request)); } return false; } if ($this->_objectionsToTransportSelection($request)) { if ($isDebugEnabled) { $logger->debug(sprintf('Event listeners turned down offer to handle %s', $request)); } return false; } if ($isDebugEnabled) { $logger->debug(sprintf('Offered to handle %s. Now initializing.', $request)); } try { $response = $this->handle($request); $context->put('response', $response); /** * Fire a success event. */ $transportSuccessEvent = new ehough_tickertape_GenericEvent($this, array('request' => $request, 'response' => $response)); $this->_eventDispatcher->dispatch(ehough_shortstop_api_Events::TRANSPORT_SUCCESS, $transportSuccessEvent); return true; } catch (Exception $e) { return $this->_handleTransportException($e, $request, $context, $isDebugEnabled, $logger); } }