Ejemplo n.º 1
0
Archivo: Proxy.php Proyecto: psagi/sdo
 /**
  * Enumerate
  *
  * @return SDO
  */
 public function enumerate()
 {
     SCA::$logger->log("Entering enumerate()");
     //TODO these should all be building a setopts array not sending a lot.
     $handle = curl_init($this->target);
     curl_setopt($handle, CURLOPT_HEADER, false);
     curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($handle, CURLOPT_HTTPGET, true);
     curl_setopt($handle, CURLOPT_ENCODING, '');
     curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, '_headerCallback'));
     $result = curl_exec($handle);
     $response_http_code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
     SCA::$logger->log("Http response code: {$response_http_code}");
     curl_close($handle);
     //convert the result into an sdo.
     $sdo = SCA_Bindings_Rss_RssDas::fromXml($result);
     //TODO: confirm the correct response code for retrieve.
     if ($response_http_code != 200) {
         switch ($response_http_code) {
             // Temporary redirects
             case 302:
             case 307:
                 // FOLLOWLOCATION is on, so we should not get here
                 throw new SCA_RuntimeException('enumerate() status code ' . $response_http_code . ' when 200 expected');
             case 503:
                 //TODO: pick out the message from the response if there is one
                 //for now just pass back a one liner.
                 throw new SCA_ServiceUnavailableException("Service Unavailable");
             case 409:
                 throw new SCA_ConflictException("Conflict");
             case 407:
                 throw new SCA_AuthenticationException("Authentication Required");
             case 400:
                 throw new SCA_BadRequestException("Bad Request");
             case 500:
                 throw new SCA_InternalServerErrorException("Internal Server Error");
             case 405:
                 throw new SCA_MethodNotAllowedException("Method Not Allowed");
             case 401:
                 throw new SCA_UnauthorizedException("Unauthorized");
             default:
                 throw new SCA_RuntimeException('enumerate() status code ' . $response_http_code . ' when 200 expected');
         }
     } else {
         return $sdo;
     }
 }