/** * Parse request string to assign object properties with command name and * arguments structure * * @param string $str */ protected function parseRequest($str = '') { $dom = new DOMDocument(); $dom->loadXML($str, LIBXML_NOBLANKS); $arr = API::convertXmlToPhpObj($dom->documentElement); list($dummy, $credentials) = each($arr); list($this->cmd, $this->args) = each($arr); $this->username = $credentials['username']; $this->password = $credentials['password']; if (isset($credentials['hash'])) { $this->hash = $credentials['hash']; } if (isset($credentials['misc'])) { $this->misc = $credentials['misc']; } $this->token = isset($credentials['token']) ? $credentials['token'] : null; $this->ip = isset($credentials['ip']) ? $credentials['ip'] : null; if (isset($credentials['language'])) { $this->language = $credentials['language']; } }
/** * Parse the reply * * @param string $str * @throws ApiException */ protected function parseReply($str = '') { $dom = new DOMDocument(); $result = $dom->loadXML(trim($str)); if (!$result) { error_log("Cannot parse xml: '{$str}'"); } $arr = API::convertXmlToPhpObj($dom->documentElement); if (!is_array($arr) && trim($arr) == "" || $arr['reply']['code'] == 4005) { throw new ApiException('API is temprorarily unavailable due to maintenance', 4005); } $this->faultCode = (int) $arr['reply']['code']; $this->faultString = $arr['reply']['desc']; $this->value = $arr['reply']['data']; if (isset($arr['reply']['warnings'])) { $this->warnings = $arr['reply']['warnings']; } if (isset($arr['reply']['maintenance'])) { $this->maintenance = $arr['reply']['maintenance']; } }