コード例 #1
0
 public function __construct($message = null, $apiType = null, $apiCode = null, $details = array(), BasicResponse $response = null)
 {
     parent::__construct($message);
     $this->setApiType($apiType);
     $this->setApiCode($apiCode);
     $this->setDetails($details);
     $this->setResponse($response);
 }
コード例 #2
0
 /**
  * Execute the request.
  * @throws CurlException
  * @throws \Quazardous\PriceministerWs\RuntimeException
  * @throws ApiException
  * @return \Quazardous\PriceministerWs\Response\BasicResponse
  */
 public function execute()
 {
     $url = $this->getOption('url') . '?' . http_build_query($this->getParameters());
     $curl = new CurlRequest($url);
     $curl->getOptions()->set(CURLOPT_TIMEOUT, $this->getOption('timeout'))->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_HEADER, true);
     $curlResponse = $curl->send();
     if ($curlResponse->hasError()) {
         $error = $curlResponse->getError();
         throw new CurlException($error ? $error->getMessage() : 'Unkown exception', $error ? $error->getCode() : null);
     }
     $code = $curlResponse->getInfo(CURLINFO_HTTP_CODE);
     $content = $curlResponse->getContent();
     $header_size = $curlResponse->getInfo(CURLINFO_HEADER_SIZE);
     $header = substr($content, 0, $header_size);
     $body = substr($content, $header_size);
     $basic = new BasicResponse($header, $body);
     $start = substr($body, 0, 256);
     $matches = null;
     if (preg_match('@<\\?xml[^>]+encoding="[^\\s"]+[^?]*\\?>\\s*<errorresponse@si', $start, $matches)) {
         $xml = simplexml_load_string($body);
         if ($xml === false) {
             throw new RuntimeException('Response content is no valid XML', RuntimeException::NO_VALID_XML);
         }
         $details = array();
         if ($xml->error->details->detail) {
             foreach ($xml->error->details->detail as $detail) {
                 $details[] = (string) $detail;
             }
         }
         throw new ApiException($xml->error->message, $xml->error->type, $xml->error->code, $details, $basic);
     }
     if ($code != 200) {
         $e = new RuntimeException('HTTP code is not 200 (' . $code . ')', RuntimeException::HTTP_CODE_NOT_200);
         $e->setResponse($basic);
         throw $e;
     }
     return $basic;
 }