summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Morken <olav.morken@uninett.no>2012-03-23 13:31:47 +0000
committerOlav Morken <olav.morken@uninett.no>2012-03-23 13:31:47 +0000
commitcad913aa72d5dba2ac98095afdb332e5a8edee6b (patch)
tree467949e1e0c55f29f7b695150d6127bac79394f3
parent2b80afe7af498d894b006ba2bde69b1036679410 (diff)
downloadsimplesamlphp-cad913aa72d5dba2ac98095afdb332e5a8edee6b.zip
simplesamlphp-cad913aa72d5dba2ac98095afdb332e5a8edee6b.tar.gz
simplesamlphp-cad913aa72d5dba2ac98095afdb332e5a8edee6b.tar.bz2
SAML2_XML_md_EndpointType: Add support for arbitrary namespace-prefixed attributes.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3058 44740490-163a-0410-bde0-09ae8108e29a
-rw-r--r--lib/SAML2/XML/md/EndpointType.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/SAML2/XML/md/EndpointType.php b/lib/SAML2/XML/md/EndpointType.php
index 519a0a7..e4317e6 100644
--- a/lib/SAML2/XML/md/EndpointType.php
+++ b/lib/SAML2/XML/md/EndpointType.php
@@ -33,6 +33,14 @@ class SAML2_XML_md_EndpointType {
/**
+ * Extra (namespace qualified) attributes.
+ *
+ * @var array
+ */
+ private $attributes = array();
+
+
+ /**
* Initialize an EndpointType.
*
* @param DOMElement|NULL $xml The XML element we should load.
@@ -56,6 +64,94 @@ class SAML2_XML_md_EndpointType {
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]);
}
@@ -81,6 +177,10 @@ class SAML2_XML_md_EndpointType {
$e->setAttribute('ResponseLocation', $this->ResponseLocation);
}
+ foreach ($this->attributes as $a) {
+ $e->setAttributeNS($a['namespaceURI'], $a['qualifiedName'], $a['value']);
+ }
+
return $e;
}