ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AffiliationDescriptor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\md;
4 
7 use SAML2\Utils;
8 
15 {
22 
28  public $ID;
29 
35  public $validUntil;
36 
43 
51  public $Extensions = array();
52 
60  public $AffiliateMember = array();
61 
69  public $KeyDescriptor = array();
70 
77  public function __construct(\DOMElement $xml = null)
78  {
79  parent::__construct($xml);
80 
81  if ($xml === null) {
82  return;
83  }
84 
85  if (!$xml->hasAttribute('affiliationOwnerID')) {
86  throw new \Exception('Missing affiliationOwnerID on AffiliationDescriptor.');
87  }
88  $this->affiliationOwnerID = $xml->getAttribute('affiliationOwnerID');
89 
90  if ($xml->hasAttribute('ID')) {
91  $this->ID = $xml->getAttribute('ID');
92  }
93 
94  if ($xml->hasAttribute('validUntil')) {
95  $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
96  }
97 
98  if ($xml->hasAttribute('cacheDuration')) {
99  $this->cacheDuration = $xml->getAttribute('cacheDuration');
100  }
101 
103 
104  $this->AffiliateMember = Utils::extractStrings($xml, Constants::NS_MD, 'AffiliateMember');
105  if (empty($this->AffiliateMember)) {
106  throw new \Exception('Missing AffiliateMember in AffiliationDescriptor.');
107  }
108 
109  foreach (Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) {
110  $this->KeyDescriptor[] = new KeyDescriptor($kd);
111  }
112  }
113 
120  public function toXML(\DOMElement $parent)
121  {
122  assert(is_string($this->affiliationOwnerID));
123  assert(is_null($this->ID) || is_string($this->ID));
124  assert(is_null($this->validUntil) || is_int($this->validUntil));
125  assert(is_null($this->cacheDuration) || is_string($this->cacheDuration));
126  assert(is_array($this->Extensions));
127  assert(is_array($this->AffiliateMember));
128  assert(!empty($this->AffiliateMember));
129  assert(is_array($this->KeyDescriptor));
130 
131  $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:AffiliationDescriptor');
132  $parent->appendChild($e);
133 
134  $e->setAttribute('affiliationOwnerID', $this->affiliationOwnerID);
135 
136  if (isset($this->ID)) {
137  $e->setAttribute('ID', $this->ID);
138  }
139 
140  if (isset($this->validUntil)) {
141  $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
142  }
143 
144  if (isset($this->cacheDuration)) {
145  $e->setAttribute('cacheDuration', $this->cacheDuration);
146  }
147 
148  Extensions::addList($e, $this->Extensions);
149 
150  Utils::addStrings($e, Constants::NS_MD, 'md:AffiliateMember', false, $this->AffiliateMember);
151 
152  foreach ($this->KeyDescriptor as $kd) {
153  $kd->toXML($e);
154  }
155 
156  $this->signElement($e, $e->firstChild);
157 
158  return $e;
159  }
160 }
__construct(\DOMElement $xml=null)
Initialize a AffiliationDescriptor.
static extractStrings(\DOMElement $parent, $namespaceURI, $localName)
Extract strings from a set of nodes.
Definition: Utils.php:610
static addStrings(\DOMElement $parent, $namespace, $name, $localized, array $values)
Append string elements.
Definition: Utils.php:659
toXML(\DOMElement $parent)
Add this AffiliationDescriptor to an EntityDescriptor.
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
signElement(\DOMElement $root, \DOMElement $insertBefore=null)
Sign the given XML element.
static xsDateTimeToTimestamp($time)
This function converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(.s+)?Z to a UNIX timestamp...
Definition: Utils.php:721
static addList(\DOMElement $parent, array $extensions)
Add a list of Extensions to the given element.
Definition: Extensions.php:70
static getList(\DOMElement $parent)
Get a list of Extensions in the given element.
Definition: Extensions.php:27