lrddmethod.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. $client = new HTTPClient();
  33. // GAAHHH, this method sucks! How about we make a better HTTPClient interface?
  34. switch ($method) {
  35. case HTTPClient::METHOD_GET:
  36. $response = $client->get($url);
  37. break;
  38. case HTTPClient::METHOD_HEAD:
  39. $response = $client->head($url);
  40. break;
  41. default:
  42. throw new Exception('Bad HTTP method.');
  43. }
  44. if ($response->getStatus() != 200) {
  45. throw new Exception('Unexpected HTTP status code.');
  46. }
  47. return $response;
  48. }
  49. }