ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
EntitiesDescriptor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\md;
4 
8 use SAML2\Utils;
9 
16 {
22  public $ID;
23 
29  public $validUntil;
30 
37 
43  public $Name;
44 
52  public $Extensions = array();
53 
59  public $children = array();
60 
66  public function __construct(\DOMElement $xml = null)
67  {
68  parent::__construct($xml);
69 
70  if ($xml === null) {
71  return;
72  }
73 
74  if ($xml->hasAttribute('ID')) {
75  $this->ID = $xml->getAttribute('ID');
76  }
77  if ($xml->hasAttribute('validUntil')) {
78  $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
79  }
80  if ($xml->hasAttribute('cacheDuration')) {
81  $this->cacheDuration = $xml->getAttribute('cacheDuration');
82  }
83  if ($xml->hasAttribute('Name')) {
84  $this->Name = $xml->getAttribute('Name');
85  }
86 
88 
89  foreach (Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
90  if ($node->localName === 'EntityDescriptor') {
91  $this->children[] = new EntityDescriptor($node);
92  } else {
93  $this->children[] = new EntitiesDescriptor($node);
94  }
95  }
96  }
97 
104  public function toXML(\DOMElement $parent = null)
105  {
106  assert(is_null($this->ID) || is_string($this->ID));
107  assert(is_null($this->validUntil) || is_int($this->validUntil));
108  assert(is_null($this->cacheDuration) || is_string($this->cacheDuration));
109  assert(is_null($this->Name) || is_string($this->Name));
110  assert(is_array($this->Extensions));
111  assert(is_array($this->children));
112 
113  if ($parent === null) {
115  $e = $doc->createElementNS(Constants::NS_MD, 'md:EntitiesDescriptor');
116  $doc->appendChild($e);
117  } else {
118  $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:EntitiesDescriptor');
119  $parent->appendChild($e);
120  }
121 
122  if (isset($this->ID)) {
123  $e->setAttribute('ID', $this->ID);
124  }
125 
126  if (isset($this->validUntil)) {
127  $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
128  }
129 
130  if (isset($this->cacheDuration)) {
131  $e->setAttribute('cacheDuration', $this->cacheDuration);
132  }
133 
134  if (isset($this->Name)) {
135  $e->setAttribute('Name', $this->Name);
136  }
137 
138  Extensions::addList($e, $this->Extensions);
139 
141  foreach ($this->children as $node) {
142  $node->toXML($e);
143  }
144 
145  $this->signElement($e, $e->firstChild);
146 
147  return $e;
148  }
149 }
__construct(\DOMElement $xml=null)
Initialize an EntitiesDescriptor.
$xml
Definition: metadata.php:240
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:225
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
Definition: Utils.php:191
Create styles array
The data for the language used.
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