diff --git a/lib/SAML2/XML/md/EndpointType.php b/lib/SAML2/XML/md/EndpointType.php index 519a0a7d37f933a0d7d8c9973eb7d9fde11ee654..e4317e607a8057e86dda4963ecf656dcadd3eb42 100644 --- a/lib/SAML2/XML/md/EndpointType.php +++ b/lib/SAML2/XML/md/EndpointType.php @@ -32,6 +32,14 @@ class SAML2_XML_md_EndpointType { public $ResponseLocation = NULL; + /** + * Extra (namespace qualified) attributes. + * + * @var array + */ + private $attributes = array(); + + /** * Initialize an EndpointType. * @@ -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; }