/** * @expectedException Services_Yadis_Exception * @expectedExceptionMessage Invalid response to Yadis protocol received: A test error */ public function testGetException() { $httpMock = new HTTP_Request2_Adapter_Mock(); $httpMock->addResponse(new HTTP_Request2_Exception('A test error', 500)); $http = new HTTP_Request2(); $http->setAdapter($httpMock); $sy = new Services_Yadis('http://example.org/openid'); $sy->setHttpRequest($http); $xrds = $sy->discover(); }
/** * Gets the Services_Yadis instance. Abstracted for testing. * * @return Services_Yadis */ public function getServicesYadis() { if ($this->yadis === null) { $this->yadis = new Services_Yadis($this->identifier); $this->yadis->setHttpRequestOptions($this->requestOptions); $this->yadis->addNamespace('openid', 'http://openid.net/xmlns/1.0'); } return $this->yadis; }
/** * Attempts to convert an XRI into a URI. In simple terms this involves * removing the "xri://" prefix and appending the remainder to the URI of * an XRI proxy such as "http://xri.net/". * * @param string $xri XRI * @param string $serviceType The Service Type * * @return string * @throws Services_Yadis_Exception * @uses Validate */ public function toUri($xri = null, $serviceType = null) { if (!is_null($serviceType)) { $this->_serviceType = (string) $serviceType; } if (isset($xri)) { $this->setXri($xri); } /** * Get rid of the xri:// prefix before assembling the URI * including any IP or DNS wildcards */ if (stripos($this->xri, 'xri://') === 0) { if (stripos($this->xri, 'xri://$ip*') === 0) { $iname = substr($xri, 10); } elseif (stripos($this->xri, 'xri://$dns*') === 0) { $iname = substr($xri, 11); } else { $iname = substr($xri, 6); } } else { $iname = $xri; } $uri = $this->getProxy() . $iname; if (!Services_Yadis::validateURI($uri)) { throw new Services_Yadis_Exception('Unable to translate XRI to a valid URI using proxy: ' . $this->getProxy()); } $this->uri = $uri; return $uri; }
/** * Add a single namespace to be utilised by the XML parser when it receives * a valid XRD document. * * @param string $namespaceKey Namespace key * @param string $namespaceUrl Namepspace URL * * @return void */ public function addNamespace($namespaceKey, $namespaceUrl) { if (!isset($namespaceKey) || !isset($namespaceUrl) || empty($namespaceKey) || empty($namespaceUrl)) { throw new Services_Yadis_Exception('Parameters must be non-empty strings'); } elseif (!Services_Yadis::validateURI($namespaceUrl)) { throw new Services_Yadis_Exception('Invalid namespace URI: ' . htmlentities($namespaceUrl, ENT_QUOTES, 'utf-8')); } elseif (array_key_exists($namespaceKey, $this->getNamespaces())) { throw new Services_Yadis_Exception('You may not redefine the "xrds" or "xrd" XML Namespaces'); } $this->namespaces[$namespaceKey] = $namespaceUrl; }
<?php // Demonstrates Yadis discovery on both a URI and an XRI set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); require_once 'Services/Yadis.php'; foreach (array('http://www.yahoo.com', '=self*shupp') as $id) { $yadis = new Services_Yadis($id); $serviceList = $yadis->discover(); foreach ($serviceList as $service) { $types = $service->getTypes(); echo $types[0], ' at ', implode(', ', $service->getUris()), PHP_EOL; echo 'Priority is ', $service->getPriority(), PHP_EOL; } }