Beispiel #1
0
 /**
  * Internal method retrieving an account from its email
  *
  * @param email (string) The mail account from which retrieve the account
  * If email is null, the first account is considered
  *
  * @return (SimpleXMLElement) The SimpleXML representation of the account
  *
  * @throws AllopassApiConfAccountNotFoundException If an email is provided but can't be found
  */
 private function _retrieveAccount($email)
 {
     // aMember code
     // use $email variable to pass XML
     $this->_xml = AllopassApiTools::xmlParseString($email);
     if (!is_object($this->_xml)) {
         throw new AllopassApiConfFileCorruptedException();
     }
     $this->_checkFile();
     $email = null;
     // clear variable to make following code work correct
     /////
     $accounts = $this->_xml->accounts->children();
     if ($email === null) {
         return $accounts[0];
     } else {
         foreach ($accounts as $account) {
             if ($account->attributes()->email == $email) {
                 return $account;
             }
         }
         throw new AllopassApiConfAccountNotFoundException();
     }
 }
Beispiel #2
0
 /**
  * Internal method performing a raw request using socket
  * 
  * @return (string[]) A 0-indexed array which contains response headers and body
  *
  * @throws AllopassApiUnavailableRessourceException If raw call to remote API fails
  */
 protected function _rawCall()
 {
     $host = AllopassApiConf::getInstance()->getHost();
     if (($socket = @fsockopen($host, AllopassApiConf::getInstance()->getNetworkPort(), $socket_errno, $socket_errstr, AllopassApiConf::getInstance()->getNetworkTimeout())) === false) {
         throw new AllopassApiUnavailableRessourceException();
     }
     $path = AllopassApiConf::getInstance()->getHost() . self::API_PATH . $this->_getPath();
     if ($this->_isHttpPost()) {
         $method = 'POST';
         $data = http_build_query($this->_parameters, '', '&');
         $length = strlen($data);
     } else {
         $method = 'GET';
         $data = '';
         $length = 0;
         $path .= self::HTTP_QUERY_CONNECTOR . http_build_query($this->_parameters, '', '&');
     }
     $headers = array();
     $headers[] = 'Host: ' . $host;
     $headers[] = 'Content-Type: application/x-www-form-urlencoded';
     $headers[] = 'User-Agent: ' . self::HTTP_USER_AGENT;
     $headers[] = 'Content-Length: ' . $length;
     $headers[] = 'Connection: close';
     $request = $method . ' ' . AllopassApiConf::getInstance()->getNetworkProtocol() . self::HTTP_CONNECTOR;
     $request .= $path . ' HTTP/' . self::HTTP_VERSION . self::HTTP_CRLF;
     $request .= implode(self::HTTP_CRLF, $headers) . self::HTTP_CRLF;
     $request .= self::HTTP_CRLF . $data;
     if (fwrite($socket, $request, strlen($request)) === false) {
         throw new AllopassApiUnavailableRessourceException();
     }
     $content = '';
     while (!feof($socket)) {
         if (($line = fread($socket, self::HTTP_CHUNK_SIZE)) === false) {
             throw new AllopassApiUnavailableRessourceException();
         }
         $content .= $line;
     }
     fclose($socket);
     $pos = strpos($content, self::HTTP_CRLF . self::HTTP_CRLF);
     if ($pos === false) {
         throw new AllopassApiUnavailableRessourceException();
     }
     $headers = substr($content, 0, $pos);
     $body = substr($content, $pos + self::HTTP_HEADER_SEPARATOR_SIZE);
     $aHeaders = explode(self::HTTP_CRLF, $headers);
     foreach ($aHeaders as &$header) {
         if (AllopassApiTools::beginsWith($header, 'Transfer-Encoding') && AllopassApiTools::endsWith($header, 'chunked')) {
             $body = $this->_decodeChunkedBody($body);
             continue;
         }
         if (AllopassApiTools::beginsWith($header, 'Content-Encoding')) {
             if (AllopassApiTools::endsWith($header, 'gzip')) {
                 $body = $this->_ungzipBody($body);
             } elseif (AllopassApiTools::endsWith($header, 'deflate')) {
                 $body = $this->_inflateBody($body);
             }
         }
     }
     return array($headers, $body);
 }
 /**
  * Constructor
  *
  * @param signature (string) Expected response signature
  * @param headers (string) HTTP headers of the response
  * @param body (string) Raw data of the response
  */
 public function __construct($signature, $headers, $body)
 {
     parent::__construct($signature, $headers, $body);
     $this->_xml = AllopassApiTools::xmlParseString($this->_body);
     $this->_verify();
 }