ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ContactPerson.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2\XML\md;
4
7
14{
21
29 public $Extensions = array();
30
36 public $Company = null;
37
43 public $GivenName = null;
44
50 public $SurName = null;
51
57 public $EmailAddress = array();
58
64 public $TelephoneNumber = array();
65
71 public $ContactPersonAttributes = array();
72
79 public function __construct(\DOMElement $xml = null)
80 {
81 if ($xml === null) {
82 return;
83 }
84
85 if (!$xml->hasAttribute('contactType')) {
86 throw new \Exception('Missing contactType on ContactPerson.');
87 }
88 $this->contactType = $xml->getAttribute('contactType');
89
91
92 $this->Company = self::getStringElement($xml, 'Company');
93 $this->GivenName = self::getStringElement($xml, 'GivenName');
94 $this->SurName = self::getStringElement($xml, 'SurName');
95 $this->EmailAddress = self::getStringElements($xml, 'EmailAddress');
96 $this->TelephoneNumber = self::getStringElements($xml, 'TelephoneNumber');
97
98 foreach ($xml->attributes as $attr) {
99 if ($attr->nodeName == "contactType") {
100 continue;
101 }
102
103 $this->ContactPersonAttributes[$attr->nodeName] = $attr->nodeValue;
104 }
105 }
106
114 private static function getStringElements(\DOMElement $parent, $name)
115 {
116 assert(is_string($name));
117
118 $e = Utils::xpQuery($parent, './saml_metadata:' . $name);
119
120 $ret = array();
121 foreach ($e as $i) {
122 $ret[] = $i->textContent;
123 }
124
125 return $ret;
126 }
127
136 private static function getStringElement(\DOMElement $parent, $name)
137 {
138 assert(is_string($name));
139
140 $e = self::getStringElements($parent, $name);
141 if (empty($e)) {
142 return null;
143 }
144 if (count($e) > 1) {
145 throw new \Exception('More than one ' . $name . ' in ' . $parent->tagName);
146 }
147
148 return $e[0];
149 }
150
157 public function toXML(\DOMElement $parent)
158 {
159 assert(is_string($this->contactType));
160 assert(is_array($this->Extensions));
161 assert(is_null($this->Company) || is_string($this->Company));
162 assert(is_null($this->GivenName) || is_string($this->GivenName));
163 assert(is_null($this->SurName) || is_string($this->SurName));
164 assert(is_array($this->EmailAddress));
165 assert(is_array($this->TelephoneNumber));
166 assert(is_array($this->ContactPersonAttributes));
167
168 $doc = $parent->ownerDocument;
169
170 $e = $doc->createElementNS(Constants::NS_MD, 'md:ContactPerson');
171 $parent->appendChild($e);
172
173 $e->setAttribute('contactType', $this->contactType);
174
175 foreach ($this->ContactPersonAttributes as $attr => $val) {
176 $e->setAttribute($attr, $val);
177 }
178
180
181 if (isset($this->Company)) {
182 Utils::addString($e, Constants::NS_MD, 'md:Company', $this->Company);
183 }
184 if (isset($this->GivenName)) {
185 Utils::addString($e, Constants::NS_MD, 'md:GivenName', $this->GivenName);
186 }
187 if (isset($this->SurName)) {
188 Utils::addString($e, Constants::NS_MD, 'md:SurName', $this->SurName);
189 }
190 if (!empty($this->EmailAddress)) {
191 Utils::addStrings($e, Constants::NS_MD, 'md:EmailAddress', false, $this->EmailAddress);
192 }
193 if (!empty($this->TelephoneNumber)) {
194 Utils::addStrings($e, Constants::NS_MD, 'md:TelephoneNumber', false, $this->TelephoneNumber);
195 }
196
197 return $e;
198 }
199}
An exception for terminatinating execution or to throw for unit testing.
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:230
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
Definition: Utils.php:191
static addString(\DOMElement $parent, $namespace, $name, $value)
Append string element.
Definition: Utils.php:635
static addStrings(\DOMElement $parent, $namespace, $name, $localized, array $values)
Append string elements.
Definition: Utils.php:659
static getStringElement(\DOMElement $parent, $name)
Retrieve the value of a child \DOMElement as a string.
__construct(\DOMElement $xml=null)
Initialize a ContactPerson element.
static getStringElements(\DOMElement $parent, $name)
Retrieve the value of a child \DOMElements as an array of strings.
toXML(\DOMElement $parent)
Convert this ContactPerson to XML.
static getList(\DOMElement $parent)
Get a list of Extensions in the given element.
Definition: Extensions.php:27
static addList(\DOMElement $parent, array $extensions)
Add a list of Extensions to the given element.
Definition: Extensions.php:70
$i
Definition: disco.tpl.php:19
$ret
Definition: parser.php:6