コード例 #1
0
ファイル: document.php プロジェクト: saschabeaumont/vuzitphp
 public static function findById($id)
 {
     $method = "show";
     $params['id'] = $id;
     $post_params = self::postParams($method, $params);
     $ch = curl_init();
     $url = self::paramsToUrl($post_params);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $xml_string = curl_exec($ch);
     $info = curl_getinfo($ch);
     if (!$xml_string) {
         throw new Vuzit_Exception('CURL load failed: "' . curl_error($ch) . '"');
     }
     // TODO: This needs to be re-added some time in the future by looking at the
     //       error codes.  I would add it but they aren't documented.
     //if($info['http_code'] != 200) {
     //  throw new Vuzit_Exception("HTTP error " . $info['http_code']);
     //}
     // Prevent the warnings if the XML is malformed
     $xml = @simplexml_load_string($xml_string);
     curl_close($ch);
     if (!$xml) {
         throw new Vuzit_Exception("Error loading XML response");
     }
     if ($xml->code) {
         throw new Vuzit_Exception($xml->msg, (int) $xml->code);
     }
     if (!$xml->web_id) {
         throw new Vuzit_Exception("Unknown error occurred");
     }
     // Success!
     $result = new Vuzit_Document();
     $result->setId($xml->web_id);
     if ($xml->title) {
         $result->setTitle($xml->title);
         $result->setSubject($xml->subject);
         $result->setPageCount($xml->page_count);
         $result->setPageWidth($xml->width);
         $result->setPageHeight($xml->height);
         $result->setFileSize($xml->file_size);
     }
     return $result;
 }