/** * 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; }