예제 #1
0
 protected function fetchUrl($url, $method = HTTPClient::METHOD_GET)
 {
     $client = new HTTPClient();
     // GAAHHH, this method sucks! How about we make a better HTTPClient interface?
     switch ($method) {
         case HTTPClient::METHOD_GET:
             $response = $client->get($url);
             break;
         case HTTPClient::METHOD_HEAD:
             $response = $client->head($url);
             break;
         default:
             throw new Exception('Bad HTTP method.');
     }
     if ($response->getStatus() != 200) {
         throw new Exception('Unexpected HTTP status code.');
     }
     return $response;
 }