/** * @param \Kdyby\Curl\Response $response * @param string $id */ public function response(Curl\Response $response, $id) { $content = array(); foreach ($response->getHeaders() as $name => $value) { $content[] = "{$name}: {$value}"; } $content = '< ' . implode("\n< ", $content); $this->write($content . "\n\n", $id); $body = $response->getResponse(); foreach ($this->formatters as $formatter) { if ($formatted = $formatter($body, $response)) { $body = $formatted; } } $this->write($body, $id); }
/** * @param string $policyNo * @param Response $response * @return bool|string */ public function savePdfFile($policyNo, Response $response) { if ($response->getHeaders()['Content-Type'] !== 'application/pdf') { return FALSE; } $body = $response->getResponse(); $filename = $this->tempDir . '/' . $policyNo . '-' . Strings::substring(md5($body), 0, 5) . '.pdf'; $this->toDelete[] = $filename; FileSystem::write($filename, $body); return $filename; }
/** * Funkce parsující stav odpovědi od LM connectu * @param CurlResponse $response * @param string $message * @return string * @throws \Exception */ private function parseResponse($response, $message = '') { $body = $response->getResponse(); $body = simplexml_load_string($body); if (!$response->isOk() || $body['status'] == 'failure') { throw new \Exception(isset($body->message) ? (string) $body->message : $response->getCode()); } else { if ($body['status'] == 'success') { return isset($body->message) ? (string) $body->message : $message; } } throw new \Exception(sprintf('Response not in expected format (%s)', htmlspecialchars($response->getResponse()))); }