lrddmethod.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Abstract class for LRDD discovery methods
  4. *
  5. * Objects that extend this class can retrieve an array of
  6. * resource descriptor links for the URI. The array consists
  7. * of XML_XRD_Element_Link elements.
  8. *
  9. * @category Discovery
  10. * @package StatusNet
  11. * @author James Walker <james@status.net>
  12. * @copyright 2010 StatusNet, Inc.
  13. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  14. * @link http://status.net/
  15. */
  16. abstract class LRDDMethod
  17. {
  18. protected $xrd = null;
  19. public function __construct() {
  20. $this->xrd = new XML_XRD();
  21. }
  22. /**
  23. * Discover interesting info about the URI
  24. *
  25. * @param string $uri URI to inquire about
  26. *
  27. * @return array of XML_XRD_Element_Link elements to discovered resource descriptors
  28. */
  29. abstract public function discover($uri);
  30. protected function fetchUrl($url, $method=HTTPClient::METHOD_GET)
  31. {
  32. // If we have a blacklist enabled, let's check against it
  33. Event::handle('UrlBlacklistTest', array($url));
  34. $client = new HTTPClient();
  35. // GAAHHH, this method sucks! How about we make a better HTTPClient interface?
  36. switch ($method) {
  37. case HTTPClient::METHOD_GET:
  38. $response = $client->get($url);
  39. break;
  40. case HTTPClient::METHOD_HEAD:
  41. $response = $client->head($url);
  42. break;
  43. default:
  44. throw new Exception('Bad HTTP method.');
  45. }
  46. if ($response->getStatus() != 200) {
  47. throw new Exception('Unexpected HTTP status code.');
  48. }
  49. return $response;
  50. }
  51. }