Example #1
0
 /**
  * Internal method performing a cURL request
  * 
  * @return (string[]) A 0-indexed array which contains response headers and body
  *
  * @throws AllopassApiUnavailableRessourceException If cURL call to remote API fails
  */
 protected function _curlCall()
 {
     $url = AllopassApiConf::getInstance()->getNetworkProtocol() . self::HTTP_CONNECTOR;
     $url .= AllopassApiConf::getInstance()->getHost() . self::API_PATH . $this->_getPath();
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_TIMEOUT, AllopassApiConf::getInstance()->getNetworkTimeout());
     curl_setopt($curl, CURLOPT_PORT, AllopassApiConf::getInstance()->getNetworkPort());
     curl_setopt($curl, CURLOPT_HEADER, true);
     curl_setopt($curl, CURLOPT_USERAGENT, self::HTTP_USER_AGENT);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     if ($this->_isHttpPost()) {
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->_parameters, '', '&'));
     } else {
         $url .= self::HTTP_QUERY_CONNECTOR . http_build_query($this->_parameters, '', '&');
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     $content = @curl_exec($curl);
     if (curl_errno($curl) > 0 || $content === false || $content == '') {
         throw new AllopassApiUnavailableRessourceException();
     }
     $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
     curl_close($curl);
     $headers = substr($content, 0, $headerSize - self::HTTP_HEADER_SEPARATOR_SIZE);
     $body = substr($content, $headerSize);
     return array($headers, $body);
 }
Example #2
0
 /**
  * Static method providing a single access-point to the class
  *
  * @return (AllopassApiConf) The class instance
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }