/** * Constructor for OMB_Service_Consumer * * Initializes an OMB_Service_Consumer object representing the OMB service * specified by $service_url. Performs a complete service discovery using * Yadis. * Throws OMB_UnsupportedServiceException if XRDS file does not specify a * complete OMB service. * * @param string $service_url The URL of the service * @param string $consumer_url An URL representing the consumer * @param OMB_Datastore $datastore An instance of a class implementing * OMB_Datastore * * @access public */ public function __construct($service_url, $consumer_url, $datastore) { $this->url = $service_url; $this->fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); $this->datastore = $datastore; $this->oauth_consumer = new OAuthConsumer($consumer_url, ''); $xrds = OMB_Yadis_XRDS::fromYadisURL($service_url, $this->fetcher); /* Detect our services. This performs a validation as well, since getService und getXRD throw exceptions on failure. */ $this->services = array(); foreach (array(OAUTH_DISCOVERY => OMB_Helper::$OAUTH_SERVICES, OMB_VERSION => OMB_Helper::$OMB_SERVICES) as $service_root => $targetservices) { $uris = $xrds->getService($service_root)->getURIs(); $xrd = $xrds->getXRD($uris[0]); foreach ($targetservices as $targetservice) { $yadis_service = $xrd->getService($targetservice); if ($targetservice == OAUTH_ENDPOINT_REQUEST) { $localid = $yadis_service->getElements('xrd:LocalID'); $this->listener_uri = $yadis_service->parser->content($localid[0]); } $uris = $yadis_service->getURIs(); $this->services[$targetservice] = $uris[0]; } } }
/** * Get a specific XRD * * Returns the OMB_Yadis_XRDS object corresponding to the given URI. * Throws an OMB_UnsupportedServiceException if the XRD is not available. * Note that getXRD tries to resolve external XRD parts as well. * * @param string $uri URI specifier of the requested XRD * * @access public * * @return OMB_Yadis_XRDS The object representing the requested XRD */ public function getXRD($uri) { $nexthash = strpos($uri, '#'); if ($nexthash === false) { throw new OMB_InvalidYadisException("‘{$uri’} does not specify a " . 'valid XML node.'); } if ($nexthash > 0) { $cururi = substr($uri, 0, $nexthash); $nexturi = substr($uri, $nexthash); return OMB_Yadis_XRDS::fromYadisURL($cururi, $this->fetcher)->getXRD($nexturi); } $id = substr($uri, 1); foreach ($this->allXrdNodes as $node) { $attrs = $this->parser->attributes($node); if (array_key_exists('xml:id', $attrs) && $attrs['xml:id'] == $id) { /* Trick the constructor into thinking this is the only node. */ $bogus_nodes = array($node); return new OMB_Yadis_XRDS($this->parser, $bogus_nodes); } } throw new OMB_UnsupportedServiceException($uri); }