- * @package OMB
- * @author Adrian Lang <mail@adrianlang.de>
- * @copyright 2009 Adrian Lang
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- **/
-
-class OMB_Yadis_XRDS extends Auth_Yadis_XRDS {
-
- protected $fetcher;
-
- /**
- * Create an instance from URL
- *
- * Constructs an OMB_Yadis_XRDS object from a given URL. A full Yadis
- * discovery is performed on the URL and the XRDS is parsed.
- * Throws an OMB_InvalidYadisException when no Yadis is discovered or the
- * detected XRDS file is broken.
- *
- * @param string $url The URL on which Yadis discovery
- * should be performed on
- * @param Auth_Yadis_HTTPFetcher $fetcher A fetcher used to get HTTP
- * resources
- *
- * @access public
- *
- * @return OMB_Yadis_XRDS The initialized object representing the given
- * resource
- **/
- public static function fromYadisURL($url, $fetcher) {
- /* Perform a Yadis discovery. */
- $yadis = Auth_Yadis_Yadis::discover($url, $fetcher);
- if ($yadis->failed) {
- throw new OMB_InvalidYadisException($url);
- }
-
- /* Parse the XRDS file. */
- $xrds = OMB_Yadis_XRDS::parseXRDS($yadis->response_text);
- if ($xrds === null) {
- throw new OMB_InvalidYadisException($url);
- }
- $xrds->fetcher = $fetcher;
- return $xrds;
- }
-
- /**
- * Get a specific service
- *
- * Returns the Auth_Yadis_Service object corresponding to the given service
- * URI.
- * Throws an OMB_UnsupportedServiceException if the service is not available.
- *
- * @param string $service URI specifier of the requested service
- *
- * @access public
- *
- * @return Auth_Yadis_Service The object representing the requested service
- **/
- public function getService($service) {
- $match = $this->services(array( create_function('$s',
- "return in_array('$service', \$s->getTypes());")));
- if ($match === array()) {
- throw new OMB_UnsupportedServiceException($service);
- }
- return $match[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 !== 0) {
- if ($nexthash !== false) {
- $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);
- }
-
- /**
- * Parse an XML string containing a XRDS document
- *
- * Parse an XML string (XRDS document) and return either a
- * Auth_Yadis_XRDS object or null, depending on whether the
- * XRDS XML is valid.
- * Copy and paste from parent to select correct constructor.
- *
- * @param string $xml_string An XRDS XML string.
- *
- * @access public
- *
- * @return mixed An instance of OMB_Yadis_XRDS or null,
- * depending on the validity of $xml_string
- **/
-
- public function &parseXRDS($xml_string, $extra_ns_map = null) {
- $_null = null;
-
- if (!$xml_string) {
- return $_null;
- }