/** * Raw operation processing * * @param Operation $operation Operation to dispatch * @return InternalError|NetworkError|Response */ public function processOperation(Operation $operation) { $template = $operation->getTemplate(); $data = $this->prepareData($operation); $parser = new Template($template, $data); $payload = $parser->parse(); $this->logEvent(LogLevel::DEBUG, $payload); $agent = new Agent($payload, $this->getEndpointUrls()); $result = $agent->dispatch(); $this->logEvent(LogLevel::DEBUG, $result); if (!$agent->isSuccess()) { $status = $agent->getStatus(); $this->logEvent(LogLevel::ALERT, 'Network error (' . $status['errcode'] . '): ' . $status['message']); return new NetworkError('Local error: ' . $status['message'], ['code' => $status['errcode']]); } $response = $parser->decode($result); $return = $operation->parseResponse($response, $this->mode); if (!$return instanceof Response) { $return = new InternalError('Local error: invalid data received from operation'); } return $return; }