Ejemplo n.º 1
0
 /**
  * @param array $data
  *
  * @return array|string|null
  *
  * @throws \Exception
  */
 public function send($data = null)
 {
     $request = new FormRequest($this->method, $this->resource, $this->host);
     if ($data) {
         $request->addFields($data);
     }
     try {
         $this->logger->addDebug('Request: ' . $request->getUrl());
         /** @var Buzz\Message\Response $response */
         $response = $this->client->send($request);
         $this->logger->addDebug('Response: ' . $response->getStatusCode() . ' ' . substr($response->getContent(), 0, 300) . PHP_EOL . var_export($this->client->getClient()->getInfo(), true));
     } catch (\Exception $e) {
         switch ($e->getCode()) {
             case 28:
                 $code = 504;
                 break;
             default:
                 $code = $e->getCode() >= 100 ? $e->getCode() : 500;
         }
         $this->logger->addCritical(PHP_EOL . __METHOD__ . sprintf('[%s/%s] %s', $e->getCode(), $code, $e->getMessage()));
         throw new WebGateException($e->getMessage(), $code, $e);
     }
     if ($response->getStatusCode() != 200) {
         throw new WebGateException(json_decode($response->getContent(), true), $response->getStatusCode());
     }
     return json_decode($response->getContent(), true);
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @param bool|false $returnXml
  *
  * @return \stdClass|array|string
  *
  * @throws WebGateException
  */
 public function send($data, $returnXml = false)
 {
     try {
         $options = ['trace' => true, 'exceptions' => true, 'connection_timeout' => $this->connectionTimeout];
         if (!empty($this->login)) {
             $options['login'] = $this->login;
             $options['password'] = $this->password;
         }
         if (0) {
             $options['location'] = '';
             $options['uri'] = '';
             $wsdl = null;
         } else {
             $wsdl = $this->wsdlPath;
         }
         $client = new \SoapClient($wsdl, $options);
         ini_set("default_socket_timeout", $this->connectionTimeout);
         $response = $client->__soapCall($this->methodName, array('params' => $data));
         $this->logger->addDebug('Response XML: ' . PHP_EOL . $client->__getLastResponse());
         $this->logger->addDebug('Response JSON: ' . PHP_EOL . json_encode($response));
         return $returnXml ? $client->__getLastResponse() : $response;
     } catch (\SoapFault $e) {
         if (isset($client)) {
             $this->logger->addDebug(PHP_EOL . __METHOD__ . ':');
             $this->logger->addDebug('Request Headers: ' . $client->__getLastRequestHeaders());
             $this->logger->addDebug('Request: ' . $client->__getLastRequest());
             $this->logger->addDebug('Response Headers: ' . $client->__getLastResponseHeaders());
             $this->logger->addDebug('Response: ' . PHP_EOL . $client->__getLastResponse());
         }
         if ($e->getCode()) {
             $code = $e->getCode();
         } else {
             $code = isset($e->faultcode) && is_numeric($e->faultcode) ? $e->faultcode : 500;
         }
         $this->logger->addCritical(PHP_EOL . __METHOD__ . sprintf('[%s/%s] %s', $e->getCode(), $code, $e->getMessage()));
         throw new WebGateException($e->getMessage(), $code, $e);
     }
 }