Source for file Yadis.php

Documentation is available at Yadis.php

  1. <?php
  2. /**
  3.  * OpenID_Discover_Yadis
  4.  * 
  5.  * PHP Version 5.2.0+
  6.  * 
  7.  * @category  Auth
  8.  * @package   OpenID
  9.  * @uses      OpenID_Discover_Interface
  10.  * @uses      OpenID_Discover
  11.  * @author    Rich Schumacher <rich.schu@gmail.com>
  12.  * @copyright 2009 Rich Schumacher
  13.  * @license   http://www.opensource.org/licenses/bsd-license.php FreeBSD
  14.  * @link      http://pearopenid.googlecode.com
  15.  */
  16.  
  17. /**
  18.  * Required files
  19.  */
  20. require_once 'OpenID/Discover.php';
  21. require_once 'OpenID/Discover/Interface.php';
  22. require_once 'OpenID/ServiceEndpoint.php';
  23. require_once 'OpenID/ServiceEndpoints.php';
  24.  
  25. /**
  26.  * Implements YADIS discovery
  27.  * 
  28.  * @category  Auth
  29.  * @package   OpenID
  30.  * @uses      OpenID_Discover_Interface
  31.  * @uses      OpenID_Discover
  32.  * @author    Rich Schumacher <rich.schu@gmail.com>
  33.  * @copyright 2009 Rich Schumacher
  34.  * @license   http://www.opensource.org/licenses/bsd-license.php FreeBSD
  35.  * @link      http://pearopenid.googlecode.com
  36.  * @see       Services_Yadis
  37.  */
  38. {
  39.     /**
  40.      * The Services_Yadis instance
  41.      * 
  42.      * @var Services_Yadis 
  43.      */
  44.     protected $yadis = null;
  45.  
  46.     /**
  47.      * Performs YADIS discovery
  48.      * 
  49.      * @throws OpenID_Discover_Exception on error
  50.      * @return OpenID_ServiceEndpoints 
  51.      */
  52.     public function discover()
  53.     {
  54.         try {
  55.             $discoveredServices $this->getServicesYadis()->discover();
  56.             if (!$discoveredServices->valid()) {
  57.                 return false;
  58.             }
  59.  
  60.             $service new OpenID_ServiceEndpoints($this->getServicesYadis()
  61.                                                         ->getYadisId());
  62.  
  63.             foreach ($discoveredServices as $discoveredService{
  64.                 $types $discoveredService->getTypes();
  65.                 if (array_key_exists($types[0]OpenID::$versionMap)) {
  66.  
  67.                     $version  $types[0];
  68.                     $localID  null;
  69.                     $localIDs $discoveredService->getElements('xrd:LocalID');
  70.  
  71.                     if (!empty($localIDs[0])) {
  72.                         $localID $localIDs[0];
  73.                     }
  74.  
  75.                     // Modify version if appropriate
  76.                     if ($localID && $version == OpenID::SERVICE_2_0_SERVER{
  77.                         $version OpenID::SERVICE_2_0_SIGNON;
  78.                     }
  79.  
  80.                     $opEndpoint new OpenID_ServiceEndpoint();
  81.                     $opEndpoint->setVersion($types[0]);
  82.                     // Choose OpenID 2.0 if it's available
  83.                     if (count($types1{
  84.                         foreach ($types as $type{
  85.                             if ($type == OpenID::SERVICE_2_0_SERVER ||
  86.                                 $type == OpenID::SERVICE_2_0_SIGNON{
  87.  
  88.                                 $opEndpoint->setVersion($type);
  89.                                 break;
  90.                             }
  91.                         }
  92.                     }
  93.                     $opEndpoint->setTypes($types);
  94.                     $opEndpoint->setURIs($discoveredService->getUris());
  95.                     $opEndpoint->setLocalID($localID);
  96.                     $opEndpoint->setSource(OpenID_Discover::TYPE_YADIS);
  97.                     
  98.                     $service->addService($opEndpoint);
  99.                 }
  100.             }
  101.  
  102.             // Add in expires information
  103.             $service->setExpiresHeader($this->getServicesYadis()
  104.                                             ->getHTTPResponse()
  105.                                             ->getHeader('Expires'));
  106.  
  107.             return $service;
  108.  
  109.         catch (Services_Yadis_Exception $e{
  110.             // Add logging or observer?
  111.             throw new OpenID_Discover_Exception($e->getMessage());
  112.         }
  113.  
  114.         // Did the identifier even respond to the initial HTTP request?
  115.         if ($this->yadis->getUserResponse(=== false{
  116.             throw new OpenID_Discover_Exception(
  117.                 'No response from identifier'
  118.             );
  119.         }
  120.     }
  121.  
  122.     /**
  123.      * Gets the Services_Yadis instance.  Abstracted for testing.
  124.      * 
  125.      * @return Services_Yadis 
  126.      */
  127.     public function getServicesYadis()
  128.     {
  129.         if ($this->yadis === null{
  130.             $this->yadis = new Services_Yadis($this->identifier);
  131.             $this->yadis->setHttpRequestOptions($this->requestOptions);
  132.             $this->yadis->addNamespace('openid''http://openid.net/xmlns/1.0');
  133.         }
  134.  
  135.         return $this->yadis;
  136.     }
  137. }
  138.  
  139. ?>

Documentation generated on Tue, 15 Dec 2009 19:01:00 -0800 by phpDocumentor 1.4.3