Auth_Yadis_Yadis
in package
This is the core of the PHP Yadis library. This is the only class a user needs to use to perform Yadis discovery. This class performs the discovery AND stores the result of the discovery.
First, require this library into your program source:
require_once "Auth/Yadis/Yadis.php";
To perform Yadis discovery, first call the "discover" method statically with a URI parameter:
$http_response = array();
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
$yadis_object = Auth_Yadis_Yadis::discover($uri,
$http_response, $fetcher);
If the discovery succeeds, $yadis_object will be an instance of . If not, it will be null. The XRDS document found during discovery should have service descriptions, which can be accessed by calling
$service_list = $yadis_object->services();
which returns an array of objects which describe each service. These objects are instances of Auth_Yadis_Service. Each object describes exactly one whole Service element, complete with all of its Types and URIs (no expansion is performed). The common use case for using the service objects returned by services() is to write one or more filter functions and pass those to services():
$service_list = $yadis_object->services(
array("filterByURI",
"filterByExtension"));
The filter functions (whose names appear in the array passed to services()) take the following form:
function myFilter($service) {
// Query $service object here. Return true if the service
// matches your query; false if not.
}
This is an example of a filter which uses a regular expression to match the content of URI tags (note that the Auth_Yadis_Service class provides a getURIs() method which you should use instead of this contrived example):
function URIMatcher($service) {
foreach ($service->getElements('xrd:URI') as $uri) {
if (preg_match("/some_pattern/",
$service->parser->content($uri))) {
return true;
}
}
return false;
}
The filter functions you pass will be called for each service object to determine which ones match the criteria your filters specify. The default behavior is that if a given service object matches ANY of the filters specified in the services() call, it will be returned. You can specify that a given service object will be returned ONLY if it matches ALL specified filters by changing the match mode of services():
$yadis_object->services(array("filter1", "filter2"),
SERVICES_YADIS_MATCH_ALL);
Services described in an XRDS should have a library which you'll probably be using. Those libraries are responsible for defining filters that can be used with the "services()" call. If you need to write your own filter, see the documentation for .
Table of Contents
- _getContentType() : string
- _getHeader() : string
- curlPresent() : mixed
- discover() : mixed
- 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.
- getHTTPFetcher() : Auth_Yadis_ParanoidHTTPFetcher|Auth_Yadis_PlainHTTPFetcher
- Returns an HTTP fetcher object. If the CURL extension is present, an instance of {@link Auth_Yadis_ParanoidHTTPFetcher} is returned. If not, an instance of {@link Auth_Yadis_PlainHTTPFetcher} is returned.
Methods
_getContentType()
public
static _getContentType(string $content_type_header) : string
Parameters
- $content_type_header : string
Tags
Return values
string —_getHeader()
public
static _getHeader(array<string|int, mixed> $header_list, array<string|int, mixed> $names) : string
Parameters
- $header_list : array<string|int, mixed>
- $names : array<string|int, mixed>
Tags
Return values
string —curlPresent()
public
static curlPresent() : mixed
Return values
mixed —discover()
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.
public
static discover(string $uri, Auth_Yadis_HTTPFetcher $fetcher[, array<string|int, mixed> $extra_ns_map = null ][, int $timeout = 20 ]) : mixed
Parameters
- $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<string|int, mixed> = null
-
An array which maps namespace names to namespace URIs to be used when parsing the Yadis XRDS document. UNUSED.
- $timeout : int = 20
-
An optional fetcher timeout, in seconds.
Return values
mixed —$obj Either null or an instance of Auth_Yadis_Yadis, depending on whether the discovery succeeded.
getHTTPFetcher()
Returns an HTTP fetcher object. If the CURL extension is present, an instance of {@link Auth_Yadis_ParanoidHTTPFetcher} is returned. If not, an instance of {@link Auth_Yadis_PlainHTTPFetcher} is returned.
public
static getHTTPFetcher([int $timeout = 20 ]) : Auth_Yadis_ParanoidHTTPFetcher|Auth_Yadis_PlainHTTPFetcher
If Auth_Yadis_CURL_OVERRIDE is defined, this method will always return a .
Parameters
- $timeout : int = 20