ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Auth_Yadis_XRDS Class Reference
+ Collaboration diagram for Auth_Yadis_XRDS:

Public Member Functions

 Auth_Yadis_XRDS ($xmlParser, $xrdNodes)
 Instantiate a Auth_Yadis_XRDS object. More...
 
 _addService ($priority, $service)
 @access private More...
 
 _parse ()
 Creates the service list using nodes from the XRDS XML document. More...
 
 services ($filters=null, $filter_mode=SERVICES_YADIS_MATCH_ANY)
 Returns a list of service objects which correspond to <Service> elements in the XRDS XML document for this object. More...
 

Static Public Member Functions

static parseXRDS ($xml_string, $extra_ns_map=null)
 Parse an XML string (XRDS document) and return either a Auth_Yadis_XRDS object or null, depending on whether the XRDS XML is valid. More...
 

Detailed Description

Definition at line 252 of file XRDS.php.

Member Function Documentation

◆ _addService()

Auth_Yadis_XRDS::_addService (   $priority,
  $service 
)

@access private

Definition at line 331 of file XRDS.php.

332 {
333 $priority = intval($priority);
334
335 if (!array_key_exists($priority, $this->serviceList)) {
336 $this->serviceList[$priority] = array();
337 }
338
339 $this->serviceList[$priority][] = $service;
340 }

Referenced by _parse().

+ Here is the caller graph for this function:

◆ _parse()

Auth_Yadis_XRDS::_parse ( )

Creates the service list using nodes from the XRDS XML document.

@access private

Definition at line 348 of file XRDS.php.

349 {
350 $this->serviceList = array();
351
352 $services = $this->parser->evalXPath('xrd:Service', $this->xrdNode);
353
354 foreach ($services as $node) {
355 $s = new Auth_Yadis_Service();
356 $s->element = $node;
357 $s->parser = $this->parser;
358
359 $priority = $s->getPriority();
360
361 if ($priority === null) {
362 $priority = SERVICES_YADIS_MAX_PRIORITY;
363 }
364
365 $this->_addService($priority, $s);
366 }
367 }
const SERVICES_YADIS_MAX_PRIORITY
The priority value used for service elements with no priority specified.
Definition: XRDS.php:37
_addService($priority, $service)
@access private
Definition: XRDS.php:331

References _addService(), and SERVICES_YADIS_MAX_PRIORITY.

Referenced by Auth_Yadis_XRDS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_XRDS()

Auth_Yadis_XRDS::Auth_Yadis_XRDS (   $xmlParser,
  $xrdNodes 
)

Instantiate a Auth_Yadis_XRDS object.

Requires an XPath instance which has been used to parse a valid XRDS document.

Definition at line 258 of file XRDS.php.

259 {
260 $this->parser = $xmlParser;
261 $this->xrdNode = $xrdNodes[count($xrdNodes) - 1];
262 $this->allXrdNodes = $xrdNodes;
263 $this->serviceList = array();
264 $this->_parse();
265 }
_parse()
Creates the service list using nodes from the XRDS XML document.
Definition: XRDS.php:348

References _parse().

Referenced by parseXRDS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseXRDS()

static Auth_Yadis_XRDS::parseXRDS (   $xml_string,
  $extra_ns_map = null 
)
static

Parse an XML string (XRDS document) and return either a Auth_Yadis_XRDS object or null, depending on whether the XRDS XML is valid.

Parameters
string$xml_stringAn XRDS XML string.
Returns
mixed $xrds An instance of Auth_Yadis_XRDS or null, depending on the validity of $xml_string

Definition at line 276 of file XRDS.php.

277 {
278 $_null = null;
279
280 if (!$xml_string) {
281 return $_null;
282 }
283
284 $parser = Auth_Yadis_getXMLParser();
285
286 $ns_map = Auth_Yadis_getNSMap();
287
288 if ($extra_ns_map && is_array($extra_ns_map)) {
289 $ns_map = array_merge($ns_map, $extra_ns_map);
290 }
291
292 if (!($parser && $parser->init($xml_string, $ns_map))) {
293 return $_null;
294 }
295
296 // Try to get root element.
297 $root = $parser->evalXPath('/xrds:XRDS[1]');
298 if (!$root) {
299 return $_null;
300 }
301
302 if (is_array($root)) {
303 $root = $root[0];
304 }
305
306 $attrs = $parser->attributes($root);
307
308 if (array_key_exists('xmlns:xrd', $attrs) &&
309 $attrs['xmlns:xrd'] != Auth_Yadis_XMLNS_XRDS) {
310 return $_null;
311 } else if (array_key_exists('xmlns', $attrs) &&
312 preg_match('/xri/', $attrs['xmlns']) &&
313 $attrs['xmlns'] != Auth_Yadis_XMLNS_XRD_2_0) {
314 return $_null;
315 }
316
317 // Get the last XRD node.
318 $xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD');
319
320 if (!$xrd_nodes) {
321 return $_null;
322 }
323
324 $xrds = new Auth_Yadis_XRDS($parser, $xrd_nodes);
325 return $xrds;
326 }
Auth_Yadis_getXMLParser()
Returns an instance of a Auth_Yadis_XMLParser subclass based on the availability of PHP extensions fo...
Definition: XML.php:331
const Auth_Yadis_XMLNS_XRDS
XRDS XML namespace.
Definition: XRDS.php:47
Auth_Yadis_getNSMap()
Definition: XRDS.php:49
const Auth_Yadis_XMLNS_XRD_2_0
XRD XML namespace.
Definition: XRDS.php:42
Auth_Yadis_XRDS($xmlParser, $xrdNodes)
Instantiate a Auth_Yadis_XRDS object.
Definition: XRDS.php:258

References Auth_Yadis_getNSMap(), Auth_Yadis_getXMLParser(), Auth_Yadis_XMLNS_XRD_2_0, Auth_Yadis_XMLNS_XRDS, and Auth_Yadis_XRDS().

Referenced by Auth_OpenID_ServiceEndpoint\consumerFromXRDS(), Auth_OpenID_ServiceEndpoint\fromXRDS(), and Auth_Yadis_ProxyResolver\query().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ services()

Auth_Yadis_XRDS::services (   $filters = null,
  $filter_mode = SERVICES_YADIS_MATCH_ANY 
)

Returns a list of service objects which correspond to <Service> elements in the XRDS XML document for this object.

Optionally, an array of filter callbacks may be given to limit the list of returned service objects. Furthermore, the default mode is to return all service objects which match ANY of the specified filters, but $filter_mode may be SERVICES_YADIS_MATCH_ALL if you want to be sure that the returned services match all the given filters. See Auth_Yadis_Yadis for detailed usage information on filter functions.

Parameters
mixed$filtersAn array of callbacks to filter the returned services, or null if all services are to be returned.
integer$filter_modeSERVICES_YADIS_MATCH_ALL or SERVICES_YADIS_MATCH_ANY, depending on whether the returned services should match ALL or ANY of the specified filters, respectively.
Returns
mixed $services An array of Auth_Yadis_Service objects if $filter_mode is a valid mode; null if $filter_mode is an invalid mode (i.e., not SERVICES_YADIS_MATCH_ANY or SERVICES_YADIS_MATCH_ALL).

Definition at line 393 of file XRDS.php.

395 {
396
397 $pri_keys = array_keys($this->serviceList);
398 sort($pri_keys, SORT_NUMERIC);
399
400 // If no filters are specified, return the entire service
401 // list, ordered by priority.
402 if (!$filters ||
403 (!is_array($filters))) {
404
405 $result = array();
406 foreach ($pri_keys as $pri) {
407 $result = array_merge($result, $this->serviceList[$pri]);
408 }
409
410 return $result;
411 }
412
413 // If a bad filter mode is specified, return null.
414 if (!in_array($filter_mode, array(SERVICES_YADIS_MATCH_ANY,
416 return null;
417 }
418
419 // Otherwise, use the callbacks in the filter list to
420 // determine which services are returned.
421 $filtered = array();
422
423 foreach ($pri_keys as $priority_value) {
424 $service_obj_list = $this->serviceList[$priority_value];
425
426 foreach ($service_obj_list as $service) {
427
428 $matches = 0;
429
430 foreach ($filters as $filter) {
431
432 if (call_user_func_array($filter, array(&$service))) {
433 $matches++;
434
435 if ($filter_mode == SERVICES_YADIS_MATCH_ANY) {
436 $pri = $service->getPriority();
437 if ($pri === null) {
439 }
440
441 if (!array_key_exists($pri, $filtered)) {
442 $filtered[$pri] = array();
443 }
444
445 $filtered[$pri][] = $service;
446 break;
447 }
448 }
449 }
450
451 if (($filter_mode == SERVICES_YADIS_MATCH_ALL) &&
452 ($matches == count($filters))) {
453
454 $pri = $service->getPriority();
455 if ($pri === null) {
457 }
458
459 if (!array_key_exists($pri, $filtered)) {
460 $filtered[$pri] = array();
461 }
462 $filtered[$pri][] = $service;
463 }
464 }
465 }
466
467 $pri_keys = array_keys($filtered);
468 sort($pri_keys, SORT_NUMERIC);
469
470 $result = array();
471 foreach ($pri_keys as $pri) {
472 $result = array_merge($result, $filtered[$pri]);
473 }
474
475 return $result;
476 }
$result
const SERVICES_YADIS_MATCH_ANY
This match mode means a given service must match ANY filters (at least one) passed to the Auth_Yadis_...
Definition: XRDS.php:31
const SERVICES_YADIS_MATCH_ALL
Require the XPath implementation.
Definition: XRDS.php:25

References $result, SERVICES_YADIS_MATCH_ALL, SERVICES_YADIS_MATCH_ANY, and SERVICES_YADIS_MAX_PRIORITY.


The documentation for this class was generated from the following file: