Source for file Discover.php
Documentation is available at Discover.php
* @author Rich Schumacher <rich.schu@gmail.com>
* @copyright 2009 Rich Schumacher
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID.php';
require_once 'Services/Yadis.php';
require_once 'Validate.php';
require_once 'OpenID/ServiceEndpoint.php';
require_once 'OpenID/ServiceEndpoints.php';
require_once 'OpenID/Discover/Exception.php';
* Implements OpenID discovery ({@link }
* http://openid.net/specs/openid-authentication-2_0.html#discovery 7.3} of the 2.0
* spec). Discovery is driver based, and currently supports YADIS discovery
* (via Services_Yadis), and HTML discovery ({@link OpenID_Discover_HTML}). Once
* completed, it will also support {@link }
* http://www.hueniverse.com/hueniverse/2009/03/the-discovery-protocol-stack.html
* Example usage for determining the OP Endpoint URL:
* $id = 'http://user.example.com';
* $discover = new OpenID_Discover($id);
* $result = $discover->discover();
* echo "Discovery failed\n";
* // Grab the highest priority service, and get it's first URI.
* $endpoint = $discover->services[0];
* $opEndpointURL = array_shift($serviceEndpoint->getURIs());
* @author Bill Shupp <hostmaster@shupp.org>
* @author Rich Schumacher <rich.schu@gmail.com>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
const TYPE_YADIS =
'Yadis';
const TYPE_HTML =
'HTML';
* List of supported discover types
* Order that discover should be performed
0 =>
OpenID_Discover::TYPE_YADIS,
10 =>
OpenID_Discover::TYPE_HTML
* The normalized version of the user supplied identifier
'follow_redirects' =>
true,
* Instance of OpenID_ServiceEndpoints
* @var OpenID_ServiceEndpoints
* Constructor. Enables libxml internal errors, normalized the identifier.
* @param mixed $identifier The user supplied identifier
* @param string $name Name of the member variable to get
* @return mixed The member variable if it exists
public function __get($name)
* Sets the HTTP_Request2 options to use
* @param array $options Array of HTTP_Request2 options
* @return OpenID_Discover for fluent interface
$this->requestOptions =
$options;
* @return bool true on success, false on failure
public function discover()
ksort(self::$discoveryOrder);
foreach (self::$discoveryOrder as $service) {
$discover =
self::_factory($service, $this->identifier);
$result =
$discover->discover();
* Provides the standard factory pattern for loading discovery drivers.
* @param string $discoverType The discovery type (driver) to load
* @param string $identifier The user supplied identifier
static private function _factory($discoverType, $identifier)
$file =
'OpenID/Discover/' .
$discoverType .
'.php';
$class =
'OpenID_Discover_' .
$discoverType;
'Unable to load driver: ' .
$discoverType
$object =
new $class($identifier);
'Requested driver does not conform to Discover interface'
* Determines if dicovered information supports a given OpenID extension
* @param string $extension The name of the extension to check, (SREG10, AX, etc)
$class =
'OpenID_Extension_' .
$extension;
'Unknown extension: ' .
$class
if (in_array($instance->getNamespace(), $service->getTypes())) {
* Static helper method for retrieving discovered information from cache if it
* exists, otherwise executing discovery and storing results if they are
* @param string $id URI Identifier to discover
* @param OpenID_Store $store Instance of OpenID_Store
* @return OpenID_Discover|falseOpenID_Discover on success, false on failure
static public function getDiscover($id, OpenID_Store_Interface $store)
$discoverCache =
$store->getDiscover($id);
$result =
$discover->discover();
// @codeCoverageIgnoreStart
// @codeCoverageIgnoreEnd
if ($discover->services->getExpiresHeader()) {
$expireDate =
new Date(strtotime($discover->services
$span =
new Date_Span($now, $expireDate);
$expire = (int)
$span->toSeconds();
$store->setDiscover($discover, $expireTime);
Documentation generated on Tue, 15 Dec 2009 19:00:53 -0800 by phpDocumentor 1.4.3