Ejemplo n.º 1
0
 /**
  * Based on an XRI, will request the XRD document located at the proxy
  * prefixed URI and parse in search of the XRI Canonical Id. This is
  * a flexible requirement. OpenID 2.0 requires the use of the Canonical
  * ID instead of the raw i-name. 2idi.com, on the other hand, does not.
  *
  * @param   string $xri
  * @return  string
  * @throws  Zend_Service_Yadis_Exception
  * @uses    Zend_Uri
  */
 public function toCanonicalId($xri = null)
 {
     if (!isset($xri) && !isset($this->_uri)) {
         require_once 'Zend/Service/Yadis/Exception.php';
         throw new Zend_Service_Yadis_Exception('No XRI passed as parameter as required unless called after Zend_Service_Yadis_Xri:toUri');
     } elseif (isset($xri)) {
         $uri = $this->toUri($xri);
     } else {
         $uri = $this->_uri;
     }
     $response = $this->_get($uri, null, $this->getHttpRequestOptions());
     if (stripos($response->getHeader('Content-Type'), 'application/xrds+xml') === false) {
         require_once 'Zend/Service/Yadis/Exception.php';
         throw new Zend_Service_Yadis_Exception('The response header indicates the response body is not an XRDS document');
     }
     $xrds = new SimpleXMLElement($response->getBody());
     $this->_namespace->registerXpathNamespaces($xrds);
     $this->_canonicalId = $xrds->xpath('/xrd:CanonicalID[last()]');
     if (!$this->_canonicalId) {
         return false;
     }
     $this->_canonicalId = $canonicalIds[count($canonicalIds) - 1];
     //var_dump($canonicalIds . __FILE__.__LINE__); exit;
     return $this->_canonicalId;
 }
Ejemplo n.º 2
0
 /**
  * Returns an array of all xrd elements located in the XRD document.
  *
  * @param SimpleXMLElement
  * @return array
  */
 protected function _getValidXrdNodes(SimpleXMLElement $xrds)
 {
     /**
      * Register all namespaces to this SimpleXMLElement.
      */
     $this->_namespace->registerXpathNamespaces($xrds);
     /**
      * Verify the XRDS resource has a root element called "xrds:XRDS".
      */
     $root = $xrds->xpath('/xrds:XRDS[1]');
     if (count($root) == 0) {
         return null;
     }
     /**
      * Check namespace urls of standard xmlns (no suffix) or xmlns:xrd
      * (if present and of priority) for validity.
      * No loss if neither exists, but they really should be.
      */
     $namespaces = $xrds->getDocNamespaces();
     if (array_key_exists('xrd', $namespaces) && $namespaces['xrd'] != 'xri://$xrd*($v*2.0)') {
         return null;
     } elseif (array_key_exists('', $namespaces) && $namespaces[''] != 'xri://$xrd*($v*2.0)') {
         return null;
     }
     /**
      * Grab the XRD elements which contains details of the service provider's
      * Server url, service types, and other details. Concrete subclass may
      * have additional requirements concerning node priority or valid position
      * in relation to other nodes. E.g. Yadis requires only using the *last*
      * node.
      */
     $xrdNodes = $xrds->xpath('/xrds:XRDS[1]/xrd:XRD');
     if (!$xrdNodes) {
         return null;
     }
     return $xrdNodes;
 }