[prev in list] [next in list] [prev in thread] [next in thread]
List: pear-cvs
Subject: [PEAR-CVS] svn: /pear/packages/Services_Yadis/tags/ Services_Yadis-0.3.0/Yadis/Exception.php Service
From: Bill_Shupp <shupp () php ! net>
Date: 2009-10-29 5:47:14
Message-ID: svn-shupp-1256795234-290043-1632847326 () svn ! php ! net
[Download RAW message or body]
shupp Thu, 29 Oct 2009 05:47:14 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=290043
Log:
Tagging the 0.3.0 release
Changed paths:
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Exception.php
(from pear/packages/Services_Yadis/trunk/Yadis/Exception.php:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Service.php
(from pear/packages/Services_Yadis/trunk/Yadis/Service.php:r289975)
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Namespace.php
(from pear/packages/Services_Yadis/trunk/Yadis/Xrds/Namespace.php:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Service.php
(from pear/packages/Services_Yadis/trunk/Yadis/Xrds/Service.php:r290041)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds.php
(from pear/packages/Services_Yadis/trunk/Yadis/Xrds.php:r290041)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xri.php
(from pear/packages/Services_Yadis/trunk/Yadis/Xri.php:r290041)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis.php
(from pear/packages/Services_Yadis/trunk/Yadis.php:r290041)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/test.php
(from pear/packages/Services_Yadis/trunk/test.php:r290041)
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/AllTests.php
(from pear/packages/Services_Yadis/trunk/tests/AllTests.php:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestConfiguration.php.dist
(from pear/packages/Services_Yadis/trunk/tests/TestConfiguration.php.dist:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestHelper.php
(from pear/packages/Services_Yadis/trunk/tests/TestHelper.php:r289975)
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/AllTests.php
(from pear/packages/Services_Yadis/trunk/tests/Yadis/AllTests.php:r289975)
A pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/AllTests.php
(from pear/packages/Services_Yadis/trunk/tests/Yadis/Xrds/AllTests.php:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/NamespaceTest.php
(from pear/packages/Services_Yadis/trunk/tests/Yadis/Xrds/NamespaceTest.php:r289975)
A + pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/XrdsTest.php
(from pear/packages/Services_Yadis/trunk/tests/Yadis/XrdsTest.php:r289975)
["svn-diffs-290043.txt" (text/x-diff)]
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Exception.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/Yadis/Exception.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Exception.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Exception.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,60 @@
+<?php
+/**
+ * Exception subclass of PEAR_Exception for Services_Yadis.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007, Pįdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author Pįdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+
+/**
+ * PEAR_Exception
+ */
+require_once 'PEAR/Exception.php';
+
+/**
+ * Services_Yadis_Exception
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author Pįdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+class Services_Yadis_Exception extends PEAR_Exception
+{
+}
+?>
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Service.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/Yadis/Service.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Service.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Service.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,206 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 PƔdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version $Id$
+ */
+
+/**
+ * The Services_Yadis_Service class represents a service parsed from the
+ * XRD node of a Yadis 1.0 XRDS document.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ */
+class Services_Yadis_Service
+{
+
+ /**
+ * Holds the Service node parsed from a Yadis XRDS document as a
+ * SimpleXMLElement object.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $_serviceNode = null;
+
+ /**
+ * Holds the Service node parsed from a Yadis XRDS document as a
+ * SimpleXMLElement object.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $_namespace = null;
+
+ /**
+ * Class constructor; initialise the object with a Service node from the
+ * XRDS document, and the current Services_Yadis_Xrds_Namespace
+ * object to provide the current namespaces for using XPath queries.
+ *
+ * @param SimpleXMLElement $serviceNode
+ * @param Services_Yadis_Xrds_Namespace $namespace
+ */
+ public function __construct(SimpleXMLElement $serviceNode, \
Services_Yadis_Xrds_Namespace $namespace) + {
+ $this->_serviceNode = $serviceNode;
+ $this->_namespace = $namespace;
+ $this->_namespace->registerXpathNamespaces($this->_serviceNode);
+ }
+
+ /**
+ * Return an array of Service Type URI strings. This method will NOT
+ * validate the resulting URIs.
+ *
+ * @return array
+ */
+ public function getTypes()
+ {
+ return $this->getElements('xrd:Type');
+ }
+
+ /**
+ * Return an array of Service Type URI strings. This method will NOT
+ * validate the resulting URIs. URI values in the array will have key
+ * values matching their priority, and be ordered based on their
+ * priority values - highest (i.e. lowest integer) priority first.
+ *
+ * @return array|boolean
+ */
+ public function getUris()
+ {
+ return $this->getElements('xrd:URI');
+ }
+
+ /**
+ * Return an array of Service Type LocalID strings.
+ *
+ * @return array|boolean
+ */
+ public function getLocalIDs()
+ {
+ return $this->getElements('xrd:LocalID');
+ }
+
+ /**
+ * Returns the Priority integer of this Service node.
+ *
+ * @return integer|boolean
+ */
+ public function getPriority()
+ {
+ $attributes = $this->_serviceNode->attributes();
+ foreach($attributes as $attribute=>$value) {
+ if($attribute == 'priority') {
+ return intval($value);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the current XRDS Service node as a SimpleXMLElement object.
+ *
+ * @return SimpleXMLElement
+ */
+ public function getSimpleXmlObject()
+ {
+ return $this->_serviceNode;
+ }
+
+ /**
+ * Return the current XRDS Service node as a DOMDocument object.
+ * This is just a simple transfer by loading the XML output from
+ * the SimpleXMLElement object into a new DOMDocument instance.
+ *
+ * @return DOMDocument
+ */
+ public function getDomObject()
+ {
+ return dom_import_simplexml($this->serviceNode);
+ }
+
+ /**
+ * Return the current Services_Yadis_Xrds_Namespace object.
+ *
+ * @return Services_Yadis_Xrds_Namespace
+ */
+ public function getNamespaceObject()
+ {
+ return $this->_namespace;
+ }
+
+ /**
+ * Return an array of the current XRDS namespaces for working with any
+ * XPath queries on the Service node.
+ *
+ * @return array
+ */
+ public function getNamespaces()
+ {
+ return $this->_namespace->getNamespaces();
+ }
+
+ /**
+ * Retrieve Elements of the current Service node by their name, and return
+ * as a SimpleXMLElement object. The Elements should be direct children of
+ * the Service node. This method basically just passes the $element string
+ * as an XPath query so it's open to other uses despite the assumed use
+ * case.
+ *
+ * @param string $name
+ * @return array|boolean
+ */
+ public function getElements($name)
+ {
+ $return = array();
+ $elements = $this->_serviceNode->xpath($name);
+ if (!is_array($elements) || count($elements) < 1) {
+ return false;
+ }
+ foreach ($elements as $element) {
+ $string = strval($element);
+ if(!empty($string)) {
+ $return[] = $string;
+ }
+ }
+ return $return;
+ }
+
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Namespace.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/Yadis/Xrds/Namespace.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Namespace.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Namespace.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,159 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 PƔdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+
+/** Validate */
+require_once 'Validate.php';
+
+/** Services_Yadis_Exception */
+require_once 'Services/Yadis/Exception.php';
+
+/**
+ * The Services_Yadis_Xrds_Namespace class is a container for namespaces
+ * which need to be registered to an XML parser in order to correctly consume
+ * an XRDS document using the parser's XPath functionality.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+class Services_Yadis_Xrds_Namespace
+{
+
+ /**
+ * Default XRDS namespaces which should always be registered.
+ *
+ * @var array
+ */
+ protected $namespaces = array(
+ 'xrds' => 'xri://$xrds',
+ 'xrd' => 'xri://$xrd*($v*2.0)'
+ );
+
+ /**
+ * Add a list (array) of additional namespaces to be utilised by the XML
+ * parser when it receives a valid XRD document.
+ *
+ * @param array $namespaces Array of namespaces to add
+ *
+ * @return void
+ */
+ public function addNamespaces(array $namespaces)
+ {
+ foreach ($namespaces as $namespaceKey=>$namespaceUrl) {
+ $this->addNamespace($namespaceKey, $namespaceUrl);
+ }
+ }
+
+ /**
+ * 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 (!Validate::uri($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;
+ }
+
+ /**
+ * Return the value of a specific namespace, or FALSE if not found.
+ *
+ * @param string $namespaceKey Namespace key
+ *
+ * @return string|boolean
+ */
+ public function getNamespace($namespaceKey)
+ {
+ if (array_key_exists($namespaceKey, $this->namespaces)) {
+ return $this->namespaces[$namespaceKey];
+ }
+ return false;
+ }
+
+ /**
+ * Returns an array of all currently set namespaces.
+ *
+ * @return array
+ */
+ public function getNamespaces()
+ {
+ return $this->namespaces;
+ }
+
+ /**
+ * Register all stored namespaces to the parameter SimpleXMLElement object.
+ *
+ * @param SimpleXMLElement $element Instance of SimpleXMLElement
+ *
+ * @return void
+ */
+ public function registerXpathNamespaces(SimpleXMLElement $element)
+ {
+ foreach ($this->namespaces as $namespaceKey => $namespaceUrl) {
+ $element->registerXPathNamespace($namespaceKey, $namespaceUrl);
+ }
+ }
+}
+?>
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Service.php \
(from rev 290041, pear/packages/Services_Yadis/trunk/Yadis/Xrds/Service.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Service.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds/Service.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,200 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 PƔdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version $Id$
+ */
+
+/** Services_Yadis_Xrds */
+require_once 'Services/Yadis/Xrds.php';
+
+/** Services_Yadis_Service */
+require_once 'Services/Yadis/Service.php';
+
+/**
+ * The Services_Yadis_Xrds_Service class is a wrapper for Service elements
+ * of an XRD document which is parsed using SimpleXML, and contains methods for
+ * retrieving data about each Service, including Type, Url and other arbitrary
+ * data added in a separate namespace, e.g. openid:Delegate for OpenID 1.1.
+ *
+ * This class extends the basic Services_Yadis_Xrds wrapper to implement a
+ * Service object specific to the Yadis Specification 1.0. XRDS itself is not
+ * an XML format ruled by Yadis, but by an OASIS proposal.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ */
+class Services_Yadis_Xrds_Service extends Services_Yadis_Xrds implements Iterator
+{
+
+ /**
+ * Establish a lowest priority integer; we'll take the upper 2^31
+ * integer limit.
+ * Highest priority is 0.
+ */
+ const SERVICE_LOWEST_PRIORITY = 2147483647;
+
+ /**
+ * Holds the last XRD node of the XRD document as required by Yadis 1.0.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $_xrdNode = null;
+
+ /**
+ * The Yadis Services resultset
+ *
+ * @var array
+ */
+ protected $_services = array();
+
+ /**
+ * Flag holding whether or not the array endpoint has been reached.
+ *
+ * @var boolean
+ */
+ protected $_valid = true;
+
+ /**
+ * Constructor; Accepts an XRD document for parsing.
+ * Parses the XRD document by <xrd:Service> element to construct an array
+ * of Services_Yadis_Service objects ordered by their priority.
+ *
+ * @param SimpleXMLElement $xrds
+ * @param Services_Yadis_Xrds_Namespace $namespace
+ */
+ public function __construct(SimpleXMLElement $xrds, \
Services_Yadis_Xrds_Namespace $namespace) + {
+ parent::__construct($xrds, $namespace);
+ /**
+ * The Yadis Specification requires we only use the last xrd node. The
+ * rest being ignored (if present for whatever reason). Important to
+ * note when writing an XRD document for multiple services - put
+ * the authentication service XRD node last.
+ */
+ $this->_xrdNode = $this->_xrdNodes[count($this->_xrdNodes) - 1];
+ $this->_namespace->registerXpathNamespaces($this->_xrdNode);
+ $services = $this->_xrdNode->xpath('xrd:Service');
+ foreach ($services as $service) {
+ $serviceObj = new Services_Yadis_Service($service, $this->_namespace);
+ $this->_addService($serviceObj);
+ }
+ $this->_services = Services_Yadis_Xrds::sortByPriority($this->_services);
+ }
+
+ /**
+ * Implements Iterator::current()
+ *
+ * Return the current element.
+ *
+ * @return Services_Yadis_Service
+ */
+ public function current()
+ {
+ return current($this->_services);
+ }
+
+ /**
+ * Implements Iterator::key()
+ *
+ * Return the key of the current element.
+ *
+ * @return integer
+ */
+ public function key()
+ {
+ return key($this->_services);
+ }
+
+ /**
+ * Implements Iterator::next()
+ *
+ * Increments pointer to next Service object.
+ *
+ * @return void
+ */
+ public function next()
+ {
+ $this->_valid = (false !== next($this->_services));
+ }
+
+ /**
+ * Implements Iterator::rewind()
+ *
+ * Rewinds the Iterator to the first Service object
+ *
+ * @return boolean
+ */
+ public function rewind()
+ {
+ $this->_valid = (false !== reset($this->_services));
+ }
+
+ /**
+ * Implement Iterator::valid()
+ *
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_valid;
+ }
+
+ /**
+ * Add a service to the Service list indexed by priority. Assumes
+ * a missing or invalid priority should be shuffled to the bottom
+ * of the priority order.
+ *
+ * @param Services_Yadis_Service $service
+ */
+ protected function _addService(Services_Yadis_Service $service)
+ {
+ $servicePriority = $service->getPriority();
+ if(is_null($servicePriority) || !is_numeric($servicePriority)) {
+ $servicePriority = self::SERVICE_LOWEST_PRIORITY;
+ }
+ if (!array_key_exists($servicePriority, $this->_services)){
+ $this->_services[$servicePriority] = array();
+ }
+ $this->_services[$servicePriority][] = $service;
+ }
+
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds.php (from \
rev 290041, pear/packages/Services_Yadis/trunk/Yadis/Xrds.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xrds.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,241 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 Pįdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author Pįdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version $Id$
+ */
+
+/** Services_Yadis_Xrds_Namespace */
+require_once 'Services/Yadis/Xrds/Namespace.php';
+
+/**
+ * The Services_Yadis_Xrds class is a wrapper for elements of an
+ * XRD document which is parsed using SimpleXML, and contains methods for
+ * retrieving data about the document. The concrete aspects of retrieving
+ * specific data elements is left to a concrete subclass.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @subpackage Yadis
+ * @author Pįdraic Brady (http://blog.astrumfutura.com)
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ */
+class Services_Yadis_Xrds
+{
+
+ /**
+ * Current key/pointer for the Iterator
+ *
+ * @var integer
+ */
+ protected $_currentKey = 0;
+
+ /**
+ * Contains the valid xrd:XRD nodes parsed from the XRD document.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $_xrdNodes = null;
+
+ /**
+ * Instance of Services_Yadis_Xrds_Namespace for managing namespaces
+ * associated with an XRDS document.
+ *
+ * @var Services_Yadis_Xrds_Namespace
+ */
+ protected $_namespace = null;
+
+ /**
+ * Constructor; parses and validates an XRD document. All access to
+ * the data held in the XML is left to a concrete subclass specific to
+ * expected XRD format and data types.
+ * Cannot be directly instantiated; must call from subclass.
+ *
+ * @param SimpleXMLElement $xrds
+ * @param Services_Yadis_Xrds_Namespace $namespace
+ */
+ protected function __construct(SimpleXMLElement $xrds, \
Services_Yadis_Xrds_Namespace $namespace) + {
+ $this->_namespace = $namespace;
+ $xrdNodes = $this->_getValidXrdNodes($xrds);
+ if (!$xrdNodes) {
+ require_once 'Services/Yadis/Exception.php';
+ throw new Services_Yadis_Exception('The XRD document was found to be \
invalid'); + }
+ $this->_xrdNodes = $xrdNodes;
+ }
+
+ /**
+ * Add a list (array) of additional namespaces to be utilised by the XML
+ * parser when it receives a valid XRD document.
+ *
+ * @param array $namespaces
+ * @return Services_Yadis
+ */
+ public function addNamespaces(array $namespaces)
+ {
+ $this->_namespace->addNamespaces($namespaces);
+ return $this;
+ }
+
+ /**
+ * Add a single namespace to be utilised by the XML parser when it receives
+ * a valid XRD document.
+ *
+ * @param string $namespace
+ * @param string $namespaceUrl
+ * @return Services_Yadis
+ */
+ public function addNamespace($namespace, $namespaceUrl)
+ {
+ $this->_namespace->addNamespace($namespace, $namespaceUrl);
+ return $this;
+ }
+
+ /**
+ * Return the value of a specific namespace.
+ *
+ * @return string|boolean
+ */
+ public function getNamespace($namespace)
+ {
+ return $this->_namespace->getNamespace($namespace);
+ }
+
+ /**
+ * Returns an array of all currently set namespaces.
+ *
+ * @return array
+ */
+ public function getNamespaces()
+ {
+ return $this->_namespace->getNamespaces();
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Order an array of elements by priority. This assumes an array form of:
+ * $array[$priority] = <array of elements with equal priority>
+ * Where multiple elements are assigned to a priority, their order in the
+ * priority array should be made random. After ordering, the array is
+ * flattened to a single array of elements for iteration.
+ *
+ * @param array $unsorted
+ * @return array
+ */
+ public static function sortByPriority(array $unsorted)
+ {
+ ksort($unsorted);
+ $flattened = array();
+ foreach ($unsorted as $priority) {
+ if (count($priority) > 1) {
+ shuffle($priority);
+ $flattened = array_merge($flattened, $priority);
+ } else {
+ $flattened[] = $priority[0];
+ }
+ }
+ return $flattened;
+ }
+
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xri.php (from \
rev 290041, pear/packages/Services_Yadis/trunk/Yadis/Xri.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xri.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis/Xri.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,396 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 PƔdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+
+/** HTTP_Request */
+require_once 'HTTP/Request.php';
+
+/** Services_Yadis_Exception */
+require_once 'Services/Yadis/Exception.php';
+
+/** Validate */
+require_once 'Validate.php';
+
+/**
+ * Provides methods for translating an XRI into a URI.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/services_yadis
+ */
+class Services_Yadis_Xri
+{
+
+ /**
+ * Hold an instance of this object per the Singleton Pattern.
+ *
+ * @var Services_Yadis_Xri
+ */
+ protected static $instance = null;
+
+ /*
+ * Array of characters which if found at the 0 index of a Yadis ID string
+ * may indicate the use of an XRI.
+ *
+ * @var array
+ */
+ protected $xriIdentifiers = array(
+ '=', '$', '!', '@', '+'
+ );
+
+ /**
+ * Default proxy to append XRI identifier to when forming a valid URI.
+ *
+ * @var string
+ */
+ protected $proxy = 'http://xri.net/';
+
+ /**
+ * Instance of Services_Yadis_Xrds_Namespace for managing namespaces
+ * associated with an XRDS document.
+ *
+ * @var Services_Yadis_Xrds_Namespace
+ */
+ protected $namespace = null;
+
+ /**
+ * The XRI string.
+ *
+ * @var string
+ */
+ protected $xri = null;
+
+ /**
+ * The URI as translated from an XRI and appended to a Proxy.
+ *
+ * @var string
+ */
+ protected $uri = null;
+
+ /**
+ * A Canonical ID if requested, and parsed from the XRDS document found
+ * by requesting the URI created from a valid XRI.
+ *
+ * @var string
+ */
+ protected $canonicalID = null;
+
+ protected $httpRequestOptions = array();
+
+ /**
+ * Stores an array of previously performed requests. The array key is a
+ * combination of the url, service type, and http request options.
+ *
+ * @see get()
+ * @var array
+ */
+ protected $requests = array();
+
+ /**
+ * Constructor; protected since this class is a singleton.
+ */
+ protected function __construct()
+ {
+ }
+
+ /**
+ * Return a singleton instance of this class.
+ *
+ * @return Services_Yadis_Xri
+ */
+ public static function getInstance()
+ {
+ if (self::$instance === null) {
+ self::$instance = new self;
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Set a Namespace object which contains all relevant namespaces
+ * for XPath queries on this Yadis resource.
+ *
+ * @param Services_Yadis_Xrds_Namespace $namespace Instance
+ *
+ * @return Services_Yadis_Xri
+ */
+ public function setNamespace(Services_Yadis_Xrds_Namespace $namespace)
+ {
+ $this->namespace = $namespace;
+ return $this;
+ }
+
+ /**
+ * Set an XRI proxy URI. A default of "http://xri.net/" is available.
+ *
+ * @param string $proxy The Proxy server URI
+ *
+ * @return Services_Yadis_Xri
+ * @throws Services_Yadis_Exception
+ */
+ public function setProxy($proxy)
+ {
+ if (!Validate::uri($proxy)) {
+ throw new Services_Yadis_Exception(
+ 'Invalid URI; unable to set as an XRI proxy'
+ );
+ }
+ $this->proxy = $proxy;
+ return $this;
+ }
+
+ /**
+ * Return the URI of the current proxy.
+ *
+ * @return string
+ */
+ public function getProxy()
+ {
+ return $this->proxy;
+ }
+
+ /**
+ * Set an XRI to be translated to a URI.
+ *
+ * @param string $xri XRI to be translated
+ *
+ * @return Services_Yadis_Xri
+ * @throws Services_Yadis_Exception
+ */
+ public function setXri($xri)
+ {
+ /**
+ * Check if the passed string is a likely XRI.
+ */
+ if (stripos($xri, 'xri://') === false
+ && !in_array($xri[0], $this->xriIdentifiers)) {
+
+ throw new Services_Yadis_Exception('Invalid XRI string submitted');
+ }
+ $this->xri = $xri;
+ return $this;
+ }
+
+ /**
+ * Return the original XRI string.
+ *
+ * @return string
+ */
+ public function getXri()
+ {
+ return $this->xri;
+ }
+
+ /**
+ * 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 (!Validate::uri($uri)) {
+ throw new Services_Yadis_Exception(
+ 'Unable to translate XRI to a valid URI using proxy: '
+ . $this->getProxy()
+ );
+ }
+ $this->uri = $uri;
+ return $uri;
+ }
+
+ /**
+ * 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;
+ }
+
+ $request = $this->get($uri, null, $this->getHttpRequestOptions());
+ if (stripos($request->getResponseHeader('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($request->getResponseBody());
+ $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;
+ }
+
+ /**
+ * Gets the Canonical ID
+ *
+ * @throws Services_Yadis_Exception if the XRI is null
+ * @return string
+ */
+ public function getCanonicalId()
+ {
+ if ($this->canonicalID !== null) {
+ return $this->canonicalID;
+ }
+ if ($this->xri === null) {
+ throw new Services_Yadis_Exception(
+ 'Unable to get a Canonical Id since no XRI value has been set'
+ );
+ }
+ $this->toCanonicalId($this->xri);
+ return $this->canonicalID;
+ }
+
+ /**
+ * Set options to be passed to the PEAR HTTP_Request constructor
+ *
+ * @param array $options Array of HTTP_Request options
+ *
+ * @return Services_Yadis_Xri
+ */
+ public function setHttpRequestOptions(array $options)
+ {
+ $this->httpRequestOptions = $options;
+ return $this;
+ }
+
+ /**
+ * Get options to be passed to the PEAR HTTP_Request constructor
+ *
+ * @return array
+ */
+ public function getHttpRequestOptions()
+ {
+ return $this->httpRequestOptions;
+ }
+
+ /**
+ * Required to request the root i-name (XRI) XRD which will provide an
+ * error message that the i-name does not exist, or else return a valid
+ * XRD document containing the i-name's Canonical ID.
+ *
+ * @param string $url URI
+ * @param string $serviceType Optional service type
+ *
+ * @return HTTP_Request
+ * @todo Finish this a bit better using the QXRI rules.
+ */
+ protected function get($url, $serviceType = null)
+ {
+ $request = new HTTP_Request($url, $this->getHttpRequestOptions());
+ $request->setMethod(HTTP_REQUEST_METHOD_GET);
+ $request->addHeader('Accept', 'application/xrds+xml');
+ if ($serviceType) {
+ $request->addQueryString('_xrd_r', 'application/xrds+xml');
+ $request->addQueryString('_xrd_t', $serviceType);
+ } else {
+ $request->addQueryString('_xrd_r', 'application/xrds+xml;sep=false');
+ }
+
+ $response = $request->sendRequest();
+ if (PEAR::isError($response)) {
+ throw new Services_Yadis_Exception(
+ 'Invalid response to Yadis protocol received: '
+ . $request->getResponseCode() . ' ' . $request->getResponseBody()
+ );
+ }
+
+ return $request;
+ }
+}
+?>
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis.php (from rev \
290041, pear/packages/Services_Yadis/trunk/Yadis.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/Yadis.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,679 @@
+<?php
+/**
+ * Implementation of the Yadis Specification 1.0 protocol for service
+ * discovery from an Identity URI/XRI or other.
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2007 PƔdraic Brady <padraic.brady@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/Services_Yadis
+ */
+
+/**
+ * required files
+ */
+require_once 'Services/Yadis/Xrds/Service.php';
+require_once 'Services/Yadis/Exception.php';
+require_once 'Services/Yadis/Xrds/Namespace.php';
+require_once 'Services/Yadis/Xri.php';
+require_once 'HTTP/Request.php';
+require_once 'Validate.php';
+
+/**
+ * Services_Yadis class
+ *
+ * Services_Yadis will provide a method of Service Discovery implemented
+ * in accordance with the Yadis Specification 1.0. This describes a protocol
+ * for locating an XRD document which details Services available. The XRD is
+ * typically specific to a single user, identified by their Yadis ID.
+ * Services_Yadis_XRDS will be a wrapper which is responsible for parsing
+ * and presenting an iterable list of Services_Yadis_Service objects
+ * holding the data for each specific Service discovered.
+ *
+ * Note that class comments cannot substitute for a full understanding of the
+ * rules and nuances required to implement the Yadis protocol. Where doubt
+ * exists, refer to the Yadis Specification 1.0 at:
+ * http://yadis.org/papers/yadis-v1.0.pdf
+ * Departures from the specification should be regarded as bugs ;).
+ *
+ * Example usage:
+ *
+ * Example 1: OpenID Service Discovery
+ *
+ * $openid = 'http://padraic.astrumfutura.com';
+ * $yadis = new Services_Yadis($openid);
+ * $yadis->addNamespace('openid', 'http://openid.net/xmlns/1.0');
+ * $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;
+ * }
+ *
+ * Possible Result @index[0] (indicates we may send Auth 2.0 requests for
+ * OpenID):
+ *
+ * http://specs.openid.net/auth/2.0/server at http://www.myopenid.com/server
+ * Priority is 0
+ *
+ * @category Services
+ * @package Services_Yadis
+ * @author PƔdraic Brady <padraic.brady@yahoo.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/Services_Yadis
+ */
+class Services_Yadis
+{
+
+ /**
+ * Constants referring to Yadis response types
+ */
+ const XRDS_META_HTTP_EQUIV = 2;
+ const XRDS_LOCATION_HEADER = 4;
+ const XRDS_CONTENT_TYPE = 8;
+
+ /**
+ * The current Yadis ID; this is the raw form initially submitted prior
+ * to any transformation/validation as an URL. This *may* allow IRI support
+ * in the future given IRIs map to URIs and adoption of the IRI standard
+ * and are entering common use internationally.
+ *
+ * @var string
+ */
+ protected $yadisId = '';
+
+ /**
+ * The current Yadis URL; this is a URL either validated or transformed
+ * from the initial Yadis ID. This URL is used to make the initial HTTP
+ * GET request during Service Discovery.
+ *
+ * @var string
+ */
+ protected $yadisUrl = '';
+
+ /**
+ * Holds the first response received during Service Discovery.
+ *
+ * This is required to allow certain Service specific fallback methods.
+ * For example, OpenID allows a Yadis fallback which relies on seeking a
+ * set of appropriate <link> elements.
+ *
+ * @var HTTP_Request
+ */
+ protected $metaHttpEquivResponse = null;
+
+ /**
+ * A URL parsed from a HTML document's <meta> element inserted in
+ * accordance with the Yadis Specification and which points to a Yadis
+ * XRD document.
+ *
+ * @var string
+ */
+ protected $metaHttpEquivUrl = '';
+
+ /**
+ * A URI parsed from an X-XRDS-Location response-header. This value must
+ * point to a Yadis XRD document otherwise the Yadis discovery process
+ * should be considered to have failed.
+ *
+ * @var string
+ */
+ protected $xrdsLocationHeaderUrl = '';
+
+ /**
+ * Instance of Services_Yadis_Xrds_Namespace for managing namespaces
+ * associated with an XRDS document.
+ *
+ * @var Services_Yadis_Xrds_Namespace
+ */
+ protected $namespace = null;
+
+ /**
+ * Array of valid HTML Content-Types. Required since Yadis states agents
+ * must parse a document if received as the first response and with an
+ * MIME type indicating HTML or XHTML. Listed in order of priority, with
+ * HTML taking priority over XHTML.
+ *
+ * @link http://www.w3.org/International/articles/serving-xhtml/Overview.en.php
+ * @var array
+ */
+ protected $validHtmlContentTypes = array(
+ 'text/html',
+ 'application/xhtml+xml',
+ 'application/xml',
+ 'text/xml'
+ );
+
+ /*
+ * Array of characters which if found at the 0 index of a Yadis ID string
+ * may indicate the use of an XRI.
+ *
+ * @var array
+ */
+ protected $xriIdentifiers = array(
+ '=', '$', '!', '@', '+'
+ );
+
+ protected $httpRequestOptions = array();
+
+ /**
+ * HTTP_Request object utilised by this class if externally set
+ *
+ * @var HTTP_Request
+ */
+ protected $httpRequest = null;
+
+ /**
+ * Class Constructor
+ *
+ * Allows settings of the initial Yadis ID (an OpenID URL for example) and
+ * an optional list of additional namespaces. For example, OpenID uses a
+ * namespace such as: xmlns:openid="http://openid.net/xmlns/1.0"
+ * Namespaces are assigned to a Services_Yadis_Xrds_Namespace container
+ * object to be passed more easily to other objects being
+ *
+ * @param string $yadisId Optional Yadis ID
+ * @param array $namespaces Optional array of namespaces
+ *
+ * @return void
+ */
+ public function __construct($yadisId = null, array $namespaces = array())
+ {
+ $this->namespace = new Services_Yadis_Xrds_Namespace;
+ $this->addNamespaces($namespaces);
+ if (isset($yadisId)) {
+ $this->setYadisId($yadisId);
+ }
+ }
+
+ /**
+ * Set options to be passed to the PEAR HTTP_Request constructor
+ *
+ * @param array $options Array of options for HTTP_Request
+ *
+ * @return Services_Yadis
+ */
+ public function setHttpRequestOptions(array $options)
+ {
+ $this->httpRequestOptions = $options;
+ return $this;
+ }
+
+ /**
+ * Get options to be passed to the PEAR HTTP_Request constructor
+ *
+ * @return array
+ */
+ public function getHttpRequestOptions()
+ {
+ return $this->httpRequestOptions;
+ }
+
+ /**
+ * A Yadis ID is usually an URL, but can also include an IRI, or XRI i-name.
+ * The initial version will support URLs as standard before examining options
+ * for supporting alternatives (IRI,XRI,i-name) since they require additional
+ * validation and conversion steps (e.g. Punycode for IRI) before use.
+ *
+ * Note: The current Validate classes currently do not have complete IDNA
+ * validation support for Internationalised Domain Names. To be addressed.
+ *
+ * @param string $yadisId The Yadis ID
+ *
+ * @return void
+ */
+ public function setYadisId($yadisId)
+ {
+ $this->yadisId = $yadisId;
+ $this->setYadisUrl($yadisId);
+ }
+
+ /**
+ * Returns the original Yadis ID string set for this class.
+ *
+ * @return string
+ */
+ public function getYadisId()
+ {
+ if (!isset($this->yadisId)) {
+ throw new Services_Yadis_Exception(
+ 'No Yadis ID has been set on this object yet'
+ );
+ }
+ return $this->yadisId;
+ }
+
+ /**
+ * Attempts to create a valid URI based on the value of the parameter
+ * which would typically be the Yadis ID.
+ * Note: This currently only supports XRI transformations.
+ *
+ * @param string $yadisId The Yadis ID
+ *
+ * @return Services_Yadis
+ * @throws Services_Yadis_Exception
+ */
+ public function setYadisUrl($yadisId)
+ {
+ /**
+ * This step should validate IDNs (see ZF-881)
+ */
+ if (Validate::uri($yadisId)) {
+ $this->yadisUrl = $yadisId;
+ return $this;
+ }
+
+ /**
+ * Check if the Yadis ID is an XRI
+ */
+ if (stripos($yadisId, 'xri://') === 0 ||
+ in_array($yadisId[0], $this->xriIdentifiers)) {
+
+ $xri = Services_Yadis_Xri::getInstance();
+
+ $xri->setHttpRequestOptions($this->getHttpRequestOptions());
+ $this->yadisUrl = $xri->setNamespace($this->namespace)->toUri($yadisId);
+ return $this;
+ }
+
+ /**
+ * The use of IRIs (International Resource Identifiers) is governed by
+ * RFC 3490-3495. Not yet available for validation in PEAR.
+ */
+ throw new Services_Yadis_Exception(
+ 'Unable to validate a Yadis ID as a URI, '
+ . 'or to transform a Yadis ID into a valid URI.'
+ );
+ }
+
+ /**
+ * Returns the Yadis URL. This will usually be identical to the Yadis ID,
+ * unless the Yadis ID (in the future) was one of IRI, XRI or i-name which
+ * required transformation to a valid URI.
+ *
+ * @return string
+ */
+ public function getYadisUrl()
+ {
+ if (!isset($this->yadisUrl)) {
+ throw new Services_Yadis_Exception(
+ 'No Yadis ID/URL has been set on this object yet'
+ );
+ }
+ return $this->yadisUrl;
+ }
+
+ /**
+ * Add a list (array) of additional namespaces to be utilised by the XML
+ * parser when it receives a valid XRD document.
+ *
+ * @param array $namespaces Array of namespaces
+ *
+ * @return Services_Yadis
+ */
+ public function addNamespaces(array $namespaces)
+ {
+ $this->namespace->addNamespaces($namespaces);
+ return $this;
+ }
+
+ /**
+ * Add a single namespace to be utilised by the XML parser when it receives
+ * a valid XRD document.
+ *
+ * @param string $namespace The namespace name
+ * @param string $namespaceUrl The namespace url
+ *
+ * @return Services_Yadis
+ */
+ public function addNamespace($namespace, $namespaceUrl)
+ {
+ $this->namespace->addNamespace($namespace, $namespaceUrl);
+ return $this;
+ }
+
+ /**
+ * Return the value of a specific namespace.
+ *
+ * @param string $namespace Namespace name
+ *
+ * @return string|null
+ */
+ public function getNamespace($namespace)
+ {
+ return $this->namespace->getNamespace($namespace);
+ }
+
+ /**
+ * Returns an array of all currently set namespaces.
+ *
+ * @return array
+ */
+ public function getNamespaces()
+ {
+ return $this->namespace->getNamespaces();
+ }
+
+ /**
+ * Performs Service Discovery, i.e. the requesting and parsing of a valid
+ * Yadis (XRD) document into a list of Services and Service Data. The
+ * return value will be an instance of Services_Yadis_Xrds which will
+ * implement SeekableIterator. Returns FALSE on failure.
+ *
+ * @return Services_Yadis_Xrds|boolean
+ * @throws Services_Yadis_Exception
+ */
+ public function discover()
+ {
+ $currentUri = $this->getYadisUrl();
+ $xrdsDocument = null;
+ $request = null;
+ $xrdStatus = false;
+
+ // Check XRI first
+ if (in_array($this->yadisId[0], $this->xriIdentifiers)) {
+ $xri = Services_Yadis_Xri::getInstance();
+ $xrds = $xri->toCanonicalID($xri->getXri());
+ echo $xrds->asXML();exit;
+ return new Services_Yadis_Xrds_Service($xrds, $this->namespace);
+ }
+
+ while ($xrdsDocument === null) {
+ $request = $this->get($currentUri);
+ if (!$this->metaHttpEquivResponse) {
+ $this->metaHttpEquivResponse = $request;
+ }
+ $responseType = $this->getResponseType($request);
+
+ /**
+ * If prior response type was a location header, or a http-equiv
+ * content value, then it should have contained a valid URI to
+ * an XRD document. Each of these when detected would set the
+ * xrdStatus flag to true.
+ */
+ if (!$responseType == self::XRDS_CONTENT_TYPE && $xrdStatus == true) {
+ throw new Services_Yadis_Exception(
+ 'Yadis protocol could not locate a valid XRD document'
+ );
+ }
+
+ /**
+ * The Yadis Spec 1.0 specifies that we must use a valid response
+ * header in preference to other responses. So even if we receive
+ * an XRDS Content-Type, if it also includes an X-XRDS-Location
+ * header we must request the Location URI and ignore the response
+ * body.
+ */
+ switch($responseType) {
+ case self::XRDS_LOCATION_HEADER:
+ $xrdStatus = true;
+ $currentUri = $this->xrdsLocationHeaderUrl;
+ break;
+ case self::XRDS_META_HTTP_EQUIV:
+ $xrdStatus = true;
+ $currentUri = $this->metaHttpEquivUrl;
+ break;
+ case self::XRDS_CONTENT_TYPE:
+ $xrdsDocument = $request->getResponseBody();
+ break;
+ default:
+ throw new Services_Yadis_Exception(
+ 'Yadis protocol could not locate a valid XRD document'
+ );
+ }
+ }
+
+ try {
+ $serviceList = $this->parseXrds($xrdsDocument);
+ } catch (PEAR_Exception $e) {
+ throw new Services_Yadis_Exception(
+ 'XRD Document could not be parsed with the following message: '
+ . $e->getMessage(), $e->getCode());
+ }
+ return $serviceList;
+ }
+
+ /**
+ * Return the very first response received when using a valid Yadis URL.
+ * This is important for Services, like OpenID, which can attempt a
+ * fallback solution in case Yadis fails, and the response came from a
+ * user's personal URL acting as an alias.
+ *
+ * @return string|boolean
+ */
+ public function getUserResponse()
+ {
+ if ($this->metaHttpEquivResponse instanceof HTTP_Request) {
+ return $this->metaHttpEquivResponse->getResponseBody();
+ }
+ return false;
+ }
+
+ /**
+ * Setter for custom HTTP_Request type object
+ *
+ * @param HTTP_Request $request Instance of HTTP_Request
+ *
+ * @return void
+ */
+ public function setHttpRequest(HTTP_Request $request)
+ {
+ $this->httpRequest = $request;
+ }
+
+ /**
+ * Gets the HTTP_Request object
+ *
+ * @return HTTP_Request
+ */
+ public function getHttpRequest()
+ {
+ return $this->httpRequest;
+ }
+
+ /**
+ * Run any instance of HTTP_Request through a set of filters to
+ * determine the Yadis Response type which in turns determines how the
+ * response should be reacted to or dealt with.
+ *
+ * @param HTTP_Request $request Instance of HTTP_Request
+ *
+ * @return integer
+ */
+ protected function getResponseType(HTTP_Request $request)
+ {
+ if ($this->isXrdsLocationHeader($request)) {
+ return self::XRDS_LOCATION_HEADER;
+ } elseif ($this->isXrdsContentType($request)) {
+ return self::XRDS_CONTENT_TYPE;
+ } elseif ($this->isMetaHttpEquiv($request)) {
+ return self::XRDS_META_HTTP_EQUIV;
+ }
+ return false;
+ }
+
+ /**
+ * Use the HTTP_Request to issue an HTTP GET request carrying the
+ * "Accept" header value of "application/xrds+xml". This can allow
+ * servers to quickly respond with a valid XRD document rather than
+ * forcing the client to follow the X-XRDS-Location bread crumb trail.
+ *
+ * @param string $url URL
+ *
+ * @return HTTP_Request
+ */
+ protected function get($url)
+ {
+ if ($this->getHttpRequest() === null) {
+ $request = new HTTP_Request($url, $this->getHttpRequestOptions());
+ } else {
+ $request = $this->getHttpRequest();
+ }
+ $request->setMethod(HTTP_REQUEST_METHOD_GET);
+ $request->addHeader('Accept', 'application/xrds+xml');
+ $response = $request->sendRequest();
+ if (PEAR::isError($response)) {
+ throw new Services_Yadis_Exception(
+ 'Invalid response to Yadis protocol received: '
+ . $request->getResponseCode() . ' ' . $request->getResponseBody()
+ );
+ }
+ return $request;
+ }
+
+ /**
+ * Checks whether the Response contains headers which detail where
+ * we can find the XRDS resource for this user. If exists, the value
+ * is set to the private $xrdsLocationHeaderUrl property.
+ *
+ * @param HTTP_Request $request Instance of HTTP_Request
+ *
+ * @return boolean
+ */
+ protected function isXrdsLocationHeader(HTTP_Request $request)
+ {
+ if ($request->getResponseHeader('x-xrds-location')) {
+ $location = $request->getResponseHeader('x-xrds-location');
+ } elseif ($request->getResponseHeader('x-yadis-location')) {
+ $location = $request->getResponseHeader('x-yadis-location');
+ }
+ if (empty($location)) {
+ return false;
+ } elseif (!Validate::uri($location)) {
+ throw new Services_Yadis_Exception(
+ 'Invalid URI found during Discovery for location of XRDS document:'
+ . htmlentities($location, ENT_QUOTES, 'utf-8')
+ );
+ }
+ $this->xrdsLocationHeaderUrl = $location;
+ return true;
+ }
+
+ /**
+ * Checks whether the Response contains the XRDS resource. It should, per
+ * the specifications always be served as application/xrds+xml
+ *
+ * @param HTTP_Request $request Instance of HTTP_Request
+ *
+ * @return boolean
+ */
+ protected function isXrdsContentType(HTTP_Request $request)
+ {
+ if (!$request->getResponseHeader('Content-Type')
+ || stripos($request->getResponseHeader('Content-Type'),
+ 'application/xrds+xml') === false) {
+
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Assuming this user is hosting a third party sourced identity under an
+ * alias personal URL, we'll need to check if the website's HTML body
+ * has a http-equiv meta element with a content attribute pointing to where
+ * we can fetch the XRD document.
+ *
+ * @param HTTP_Request $request Instance of HTTP_Request
+ *
+ * @return boolean
+ * @throws Services_Yadis_Exception
+ */
+ protected function isMetaHttpEquiv(HTTP_Request $request)
+ {
+ $location = null;
+ if (!in_array($request->getResponseHeader('Content-Type'),
+ $this->validHtmlContentTypes)) {
+
+ return false;
+ }
+
+ /**
+ * Find a match for a relevant <meta> element, then iterate through the
+ * results to see if a valid http-equiv value and matching content URI
+ * exist.
+ */
+ $html = new DOMDocument();
+ $html->loadHTML($request->getResponseBody());
+ $head = $html->getElementsByTagName('head');
+ if ($head->length > 0) {
+ $metas = $head->item(0)->getElementsByTagName('meta');
+ if ($metas->length > 0) {
+ foreach ($metas as $meta) {
+ $equiv = strtolower($meta->getAttribute('http-equiv'));
+ if ($equiv == 'x-xrds-location'
+ || $equiv == 'x-yadis-location') {
+
+ $location = $meta->getAttribute('content');
+ }
+ }
+ }
+ }
+
+ if (is_null($location)) {
+ return false;
+ } elseif (!Validate::uri($location)) {
+ throw new Services_Yadis_Exception(
+ 'The URI parsed from the HTML Alias document appears to be invalid, \
' + . 'or could not be found: '
+ . htmlentities($location, ENT_QUOTES, 'utf-8')
+ );
+ }
+ /**
+ * Should now contain the content value of the http-equiv type pointing
+ * to an XRDS resource for the user's Identity Provider, as found by
+ * passing the meta regex across the response body.
+ */
+ $this->metaHttpEquivUrl = $location;
+ return true;
+ }
+
+ /**
+ * Creates a new Services_Yadis_Xrds object which uses SimpleXML to
+ * parse the XML into a list of Iterable Services_Yadis_Service
+ * objects.
+ *
+ * @param string $xrdsDocument The plaintext XRDS document
+ *
+ * @return Services_Yadis_Xrds|boolean
+ */
+ protected function parseXrds($xrdsDocument)
+ {
+ $xrds = new SimpleXMLElement($xrdsDocument);
+ return new Services_Yadis_Xrds_Service($xrds, $this->namespace);
+ }
+
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/test.php (from rev \
290041, pear/packages/Services_Yadis/trunk/test.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/test.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/test.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,13 @@
+<?php
+
+set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
+
+require_once 'Services/Yadis.php';
+// $yadis = new Services_Yadis('http://www.yahoo.com/');
+$yadis = new Services_Yadis('=self*shupp');
+$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;
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/AllTests.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/AllTests.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/AllTests.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/AllTests.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,37 @@
+<?php
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Services_Yadis_AllTests::main');
+}
+
+require_once 'PHPUnit/Framework/TestSuite.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once 'TestHelper.php';
+require_once 'Yadis/AllTests.php';
+
+class Services_Yadis_AllTests
+{
+ public static function main()
+ {
+ $parameters = array();
+
+ if (TESTS_GENERATE_REPORT && extension_loaded('xdebug')) {
+ $parameters['reportDirectory'] = TESTS_GENERATE_REPORT_TARGET;
+ }
+ PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('PEAR - Services_Yadis');
+
+ $suite->addTestSuite(Yadis_AllTests::suite());
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Services_Yadis_AllTests::main') {
+ Services_Yadis_AllTests::main();
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestConfiguration.php.dist \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/TestConfiguration.php.dist)
===================================================================
(Binary files differ)
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestHelper.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/TestHelper.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestHelper.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/TestHelper.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,17 @@
+<?php
+
+error_reporting( E_ALL );
+date_default_timezone_set('Europe/London');
+
+$prRoot = dirname(dirname(__FILE__));
+$prTests = $prRoot . DIRECTORY_SEPARATOR . 'tests';
+
+set_include_path($prRoot . PATH_SEPARATOR
+ . $prTests . PATH_SEPARATOR
+ . get_include_path());
+
+if (is_readable($prTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
+ require_once 'TestConfiguration.php';
+} else {
+ require_once 'TestConfiguration.php.dist';
+}
\ No newline at end of file
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/AllTests.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/Yadis/AllTests.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/AllTests.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/AllTests.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,39 @@
+<?php
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Yadis_AllTests::main');
+}
+
+require_once 'PHPUnit/Framework/TestSuite.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+require_once 'XrdsTest.php';
+require_once 'Xrds/AllTests.php';
+
+class Yadis_AllTests
+{
+ public static function main()
+ {
+ $parameters = array();
+
+ if (TESTS_GENERATE_REPORT && extension_loaded('xdebug')) {
+ $parameters['reportDirectory'] = TESTS_GENERATE_REPORT_TARGET;
+ }
+ PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('PEAR - Services_Yadis/Yadis');
+
+ $suite->addTestSuite(Yadis_Xrds_AllTests::suite());
+ $suite->addTestSuite('Services_Yadis_XrdsTest');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Yadis_AllTests::main') {
+ AllTests::main();
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/AllTests.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/Yadis/Xrds/AllTests.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/AllTests.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/AllTests.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,37 @@
+<?php
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Yadis_Xrds_AllTests::main');
+}
+
+require_once 'PHPUnit/Framework/TestSuite.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . \
'TestHelper.php'; +require_once 'NamespaceTest.php';
+
+class Yadis_Xrds_AllTests
+{
+ public static function main()
+ {
+ $parameters = array();
+
+ if (TESTS_GENERATE_REPORT && extension_loaded('xdebug')) {
+ $parameters['reportDirectory'] = TESTS_GENERATE_REPORT_TARGET;
+ }
+ PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('PEAR - \
Services_Yadis/Yadis/Xrds'); +
+ $suite->addTestSuite('Services_Yadis_Xrds_NamespaceTest');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Yadis_Xrds_AllTests::main') {
+ AllTests::main();
+}
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/NamespaceTest.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/Yadis/Xrds/NamespaceTest.php)
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/NamespaceTest.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/Xrds/NamespaceTest.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,56 @@
+<?php
+
+require_once 'Services/Yadis/Xrds/Namespace.php';
+require_once 'PHPUnit/Framework/TestCase.php';
+
+class Services_Yadis_Xrds_NamespaceTest extends PHPUnit_Framework_TestCase
+{
+
+ public function testInitialState()
+ {
+ $name = new Services_Yadis_Xrds_Namespace;
+ $this->assertEquals(array('xrds' => 'xri://$xrds','xrd' => \
'xri://$xrd*($v*2.0)'), $name->getNamespaces()); + }
+
+ public function testAddNamespace()
+ {
+ $name = new Services_Yadis_Xrds_Namespace;
+ $name->addNamespace('test', 'http://example.com/test');
+ $this->assertEquals('http://example.com/test', $name->getNamespace('test'));
+ }
+
+ public function testAddNamespaces()
+ {
+ $initial = array(
+ 'xrds' => 'xri://$xrds',
+ 'xrd' => 'xri://$xrd*($v*2.0)'
+ );
+ $spaces = array(
+ 'test'=>'http://example.com/test',
+ 'test2'=>'http://example.com/test'
+ );
+ $name = new Services_Yadis_Xrds_Namespace;
+ $name->addNamespaces($spaces);
+ $this->assertEquals($initial + $spaces, $name->getNamespaces());
+ }
+
+ // tests that if provider changes namespaces, our code's XPath can still
+ // substitute the prior prefix
+ 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]);
+ }
+
+}
\ No newline at end of file
Copied: pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/XrdsTest.php \
(from rev 289975, pear/packages/Services_Yadis/trunk/tests/Yadis/XrdsTest.php) \
===================================================================
--- pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/XrdsTest.php \
(rev 0)
+++ pear/packages/Services_Yadis/tags/Services_Yadis-0.3.0/tests/Yadis/XrdsTest.php 2009-10-29 \
05:47:14 UTC (rev 290043) @@ -0,0 +1,19 @@
+<?php
+
+require_once 'Services/Yadis/Xrds.php';
+require_once 'PHPUnit/Framework/TestCase.php';
+
+class Services_Yadis_XrdsTest extends PHPUnit_Framework_TestCase
+{
+ protected $_namespace = null;
+
+ public function setUp()
+ {
+ $this->_namespace = $this->getMock('Services_Yadis_Xrds_Namespace');
+ }
+
+ public function test()
+ {
+ }
+
+}
\ No newline at end of file
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic