Skip to content
Snippets Groups Projects
Commit cad913aa authored by Olav Morken's avatar Olav Morken
Browse files

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
parent 2b80afe7
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,14 @@ class SAML2_XML_md_EndpointType { ...@@ -32,6 +32,14 @@ class SAML2_XML_md_EndpointType {
public $ResponseLocation = NULL; public $ResponseLocation = NULL;
/**
* Extra (namespace qualified) attributes.
*
* @var array
*/
private $attributes = array();
/** /**
* Initialize an EndpointType. * Initialize an EndpointType.
* *
...@@ -56,6 +64,94 @@ class SAML2_XML_md_EndpointType { ...@@ -56,6 +64,94 @@ class SAML2_XML_md_EndpointType {
if ($xml->hasAttribute('ResponseLocation')) { if ($xml->hasAttribute('ResponseLocation')) {
$this->ResponseLocation = $xml->getAttribute('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 { ...@@ -81,6 +177,10 @@ class SAML2_XML_md_EndpointType {
$e->setAttribute('ResponseLocation', $this->ResponseLocation); $e->setAttribute('ResponseLocation', $this->ResponseLocation);
} }
foreach ($this->attributes as $a) {
$e->setAttributeNS($a['namespaceURI'], $a['qualifiedName'], $a['value']);
}
return $e; return $e;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment