Auth_Yadis_Yadis::discover PHP Method

discover() static public method

This should be called statically and will build a Yadis instance if the discovery process succeeds. This implements Yadis discovery as specified in the Yadis specification.
static public discover ( string $uri, Auth_Yadis_HTTPFetcher $fetcher, array $extra_ns_map = null, integer $timeout = 20 ) : mixed
$uri string The URI on which to perform Yadis discovery.
$fetcher Auth_Yadis_HTTPFetcher An instance of a Auth_Yadis_HTTPFetcher subclass.
$extra_ns_map array An array which maps namespace names to namespace URIs to be used when parsing the Yadis XRDS document.
$timeout integer An optional fetcher timeout, in seconds.
return mixed $obj Either null or an instance of Auth_Yadis_Yadis, depending on whether the discovery succeeded.
    static function discover($uri, $fetcher, $extra_ns_map = null, $timeout = 20)
    {
        $result = new Auth_Yadis_DiscoveryResult($uri);
        $request_uri = $uri;
        $headers = array("Accept: " . Auth_Yadis_CONTENT_TYPE . ', text/html; q=0.3, application/xhtml+xml; q=0.5');
        if ($fetcher === null) {
            $fetcher = Auth_Yadis_Yadis::getHTTPFetcher($timeout);
        }
        $response = $fetcher->get($uri, $headers);
        if (!$response || ($response->status != 200 and $response->status != 206)) {
            $result->fail();
            return $result;
        }
        $result->normalized_uri = $response->final_url;
        $result->content_type = Auth_Yadis_Yadis::_getHeader($response->headers, array('content-type'));
        if ($result->content_type && Auth_Yadis_Yadis::_getContentType($result->content_type) == Auth_Yadis_CONTENT_TYPE) {
            $result->xrds_uri = $result->normalized_uri;
        } else {
            $yadis_location = Auth_Yadis_Yadis::_getHeader($response->headers, array(Auth_Yadis_HEADER_NAME));
            if (!$yadis_location) {
                $parser = new Auth_Yadis_ParseHTML();
                $yadis_location = $parser->getHTTPEquiv($response->body);
            }
            if ($yadis_location) {
                $result->xrds_uri = $yadis_location;
                $response = $fetcher->get($yadis_location);
                if (!$response || ($response->status != 200 and $response->status != 206)) {
                    $result->fail();
                    return $result;
                }
                $result->content_type = Auth_Yadis_Yadis::_getHeader($response->headers, array('content-type'));
            }
        }
        $result->response_text = $response->body;
        return $result;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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;
 }
All Usage Examples Of Auth_Yadis_Yadis::discover