Revision: 3058
Author: olavmrk
Date: Fri Mar 23 06:31:47 2012
Log: SAML2_XML_md_EndpointType: Add support for arbitrary
namespace-prefixed attributes.
http://code.google.com/p/simplesamlphp/source/detail?r=3058
Modified:
/trunk/lib/SAML2/XML/md/EndpointType.php
=======================================
--- /trunk/lib/SAML2/XML/md/EndpointType.php Wed Apr 21 05:56:08 2010
+++ /trunk/lib/SAML2/XML/md/EndpointType.php Fri Mar 23 06:31:47 2012
@@ -32,6 +32,14 @@
public $ResponseLocation = NULL;
+ /**
+ * Extra (namespace qualified) attributes.
+ *
+ * @var array
+ */
+ private $attributes = array();
+
+
/**
* Initialize an EndpointType.
*
@@ -56,6 +64,94 @@
if ($xml->hasAttribute('ResponseLocation')) {
$this->ResponseLocation =
$xml->getAttribute('ResponseLocation');
}
+
+ foreach ($xml->attributes as $a) {
+ if ($a->namespaceURI === NULL) {
+ continue; /* Not namespace-qualified -- skip. */
+ }
+ $fullName = '{' . $a->namespaceURI . '}' .
$a->localName;
+ $this->attributes[$fullName] = array(
+ 'qualifiedName' => $a->nodeName,
+ 'namespaceURI' => $a->namespaceURI,
+ 'value' => $a->value,
+ );
+ }
+ }
+
+
+ /**
+ * Check if a namespace-qualified attribute exists.
+ *
+ * @param string $namespaceURI The namespace URI.
+ * @param string $localName The local name.
+ * @return boolean TRUE if the attribute exists, FALSE if not.
+ */
+ public function hasAttributeNS($namespaceURI, $localName) {
+ assert('is_string($namespaceURI)');
+ assert('is_string($localName)');
+
+ $fullName = '{' . $namespaceURI . '}' . $localName;
+ return isset($this->attributes[$fullName]);
+ }
+
+
+ /**
+ * Get a namespace-qualified attribute.
+ *
+ * @param string $namespaceURI The namespace URI.
+ * @param string $localName The local name.
+ * @return string The value of the attribute, or an empty string if the
attribute does not exist.
+ */
+ public function getAttributeNS($namespaceURI, $localName) {
+ assert('is_string($namespaceURI)');
+ assert('is_string($localName)');
+
+ $fullName = '{' . $namespaceURI . '}' . $localName;
+ if (!isset($this->attributes[$fullName])) {
+ return '';
+ }
+ return $this->attributes[$fullName]['value'];
+ }
+
+
+ /**
+ * Get a namespace-qualified attribute.
+ *
+ * @param string $namespaceURI The namespace URI.
+ * @param string $qualifiedName The local name.
+ * @param string $value The attribute value.
+ */
+ public function setAttributeNS($namespaceURI, $qualifiedName, $value) {
+ assert('is_string($namespaceURI)');
+ assert('is_string($qualifiedName)');
+
+ $name = explode(':', $qualifiedName, 2);
+ if (count($name) < 2) {
+ throw new Exception('Not a qualified name.');
+ }
+ $localName = $name[1];
+
+ $fullName = '{' . $namespaceURI . '}' . $localName;
+ $this->attributes[$fullName] = array(
+ 'qualifiedName' => $qualifiedName,
+ 'namespaceURI' => $namespaceURI,
+ 'value' => $value,
+ );
+ }
+
+
+ /**
+ * Remove a namespace-qualified attribute.
+ *
+ * @param string $namespaceURI The namespace URI.
+ * @param string $localName The local name.
+ */
+ public function removeAttributeNS($namespaceURI, $localName) {
+ assert('is_string($namespaceURI)');
+ assert('is_string($localName)');
+
+ $fullName = '{' . $namespaceURI . '}' . $localName;
+ unset($this->attributes[$fullName]);
}
@@ -80,6 +176,10 @@
if (isset($this->ResponseLocation)) {
$e->setAttribute('ResponseLocation',
$this->ResponseLocation);
}
+
+ foreach ($this->attributes as $a) {
+ $e->setAttributeNS($a['namespaceURI'], $a['qualifiedName'],
$a['value']);
+ }
return $e;
}
--
You received this message because you are subscribed to the Google Groups
"simpleSAMLphp commits" group.
To post to this group, send email to simplesamlphp-commits@googlegroups.com.
To unsubscribe from this group, send email to
simplesamlphp-commits+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/simplesamlphp-commits?hl=en.