Esempio n. 1
4
    public function testRegisterXpathNamespaces()
    {
        $string = <<<XML
<a xmlns:t2="http://example.com/t">
 <b>
  <t2:c>text</t2:c>
 </b>
</a>
XML;
        $xml = new SimpleXMLElement($string);
        $name = new Services_Yadis_Xrds_Namespace();
        $name->addNamespace('t', 'http://example.com/t');
        $name->registerXpathNamespaces($xml);
        $c = $xml->xpath('//t:c');
        $this->assertEquals('text', (string) $c[0]);
    }
Esempio 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)') {
         // Hack for the namespace declaration in the XRD node, which SimpleXML misses
         $xrdHack = false;
         if (!isset($xrds->XRD)) {
             return null;
         }
         foreach ($xrds->XRD as $xrd) {
             $namespaces = $xrd->getNamespaces();
             if (array_key_exists('', $namespaces) && $namespaces[''] == 'xri://$xrd*($v*2.0)') {
                 $xrdHack = true;
                 break;
             }
         }
         if (!$xrdHack) {
             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;
 }
Esempio n. 3
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 The XRI
  *
  * @todo Imcomplete; requires interface from Yadis main class
  * @return string
  * @throws Services_Yadis_Exception
  */
 public function toCanonicalId($xri = null)
 {
     if (!isset($xri) && !isset($this->uri)) {
         throw new Services_Yadis_Exception('No XRI passed as parameter as required unless called after ' . 'Services_Yadis_Xri:toUri');
     } elseif (isset($xri)) {
         $uri = $this->toUri($xri);
     } else {
         $uri = $this->uri;
     }
     $this->httpResponse = $this->get($uri, null, $this->getHttpRequestOptions());
     if (stripos($this->httpResponse->getHeader('Content-Type'), 'application/xrds+xml') === false) {
         throw new Services_Yadis_Exception('The response header indicates the response body is not ' . 'an XRDS document');
     }
     $xrds = new SimpleXMLElement($this->httpResponse->getBody());
     $this->namespace->registerXpathNamespaces($xrds);
     $id = $xrds->xpath('//xrd:CanonicalID[last()]');
     $this->canonicalID = (string) array_shift($id);
     if (!$this->canonicalID) {
         throw new Services_Yadis_Exception('Unable to determine canonicalID');
     }
     return $xrds;
 }
Esempio n. 4
0
 /**
  * Returns an array of all currently set namespaces.
  *
  * @return array
  */
 public function getNamespaces()
 {
     return $this->namespace->getNamespaces();
 }