ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AttributeValue.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2\XML\saml;
4
8
14class AttributeValue implements \Serializable
15{
21 public $element;
22
31 public function __construct($value)
32 {
33 assert(is_string($value) || $value instanceof \DOMElement);
34
35 if (is_string($value)) {
37 $this->element = $doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue');
38 $this->element->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:string');
39 $this->element->appendChild($doc->createTextNode($value));
40
41 /* Make sure that the xs-namespace is available in the AttributeValue (for xs:string). */
42 $this->element->setAttributeNS(Constants::NS_XS, 'xs:tmp', 'tmp');
43 $this->element->removeAttributeNS(Constants::NS_XS, 'tmp');
44
45 return;
46 }
47
48 if ($value->namespaceURI === Constants::NS_SAML && $value->localName === 'AttributeValue') {
49 $this->element = Utils::copyElement($value);
50
51 return;
52 }
53
55 $this->element = $doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue');
56 Utils::copyElement($value, $this->element);
57 }
58
65 public function toXML(\DOMElement $parent)
66 {
67 assert($this->element instanceof \DOMElement);
68 assert($this->element->namespaceURI === \SAML2\Constants::NS_SAML && $this->element->localName === "AttributeValue");
69
70 $v = Utils::copyElement($this->element, $parent);
71
72 return $v;
73 }
74
78 public function getString()
79 {
80 return $this->element->textContent;
81 }
82
90 public function __toString()
91 {
92 assert($this->element instanceof \DOMElement);
93
94 $doc = $this->element->ownerDocument;
95
96 $ret = '';
97 foreach ($this->element->childNodes as $c) {
98 $ret .= $doc->saveXML($c);
99 }
100
101 return $ret;
102 }
103
104
110 public function serialize()
111 {
112 return serialize($this->element->ownerDocument->saveXML($this->element));
113 }
114
115
121 public function unserialize($serialized)
122 {
123 $doc = DOMDocumentFactory::fromString(unserialize($serialized));
124 $this->element = $doc->documentElement;
125 }
126}
An exception for terminatinating execution or to throw for unit testing.
const NS_XS
The namespace fox XML schema.
Definition: Constants.php:230
const NS_XSI
The namespace for XML schema instance.
Definition: Constants.php:235
const NS_SAML
The namespace for the SAML 2 assertions.
Definition: Constants.php:220
getString()
Returns a plain text content of the attribute value.
toXML(\DOMElement $parent)
Append this attribute value to an element.
__construct($value)
Create an AttributeValue.
__toString()
Convert this attribute value to a string.
unserialize($serialized)
Un-serialize this AttributeValue.
serialize()
Serialize this AttributeValue.
$ret
Definition: parser.php:6