99 parent::__construct(
$xml);
105 if (!
$xml->hasAttribute(
'entityID')) {
106 throw new \Exception(
'Missing required attribute entityID on EntityDescriptor.');
108 $this->entityID =
$xml->getAttribute(
'entityID');
110 if (
$xml->hasAttribute(
'ID')) {
111 $this->ID =
$xml->getAttribute(
'ID');
113 if (
$xml->hasAttribute(
'validUntil')) {
116 if (
$xml->hasAttribute(
'cacheDuration')) {
117 $this->cacheDuration =
$xml->getAttribute(
'cacheDuration');
122 for ($node =
$xml->firstChild; $node !== null; $node = $node->nextSibling) {
131 switch ($node->localName) {
132 case 'RoleDescriptor':
135 case 'IDPSSODescriptor':
138 case 'SPSSODescriptor':
141 case 'AuthnAuthorityDescriptor':
144 case 'AttributeAuthorityDescriptor':
147 case 'PDPDescriptor':
153 $affiliationDescriptor =
Utils::xpQuery(
$xml,
'./saml_metadata:AffiliationDescriptor');
154 if (count($affiliationDescriptor) > 1) {
155 throw new \Exception(
'More than one AffiliationDescriptor in the entity.');
156 } elseif (!empty($affiliationDescriptor)) {
161 throw new \Exception(
'Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.');
163 throw new \Exception(
'AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.');
167 if (count($organization) > 1) {
168 throw new \Exception(
'More than one Organization in the entity.');
169 } elseif (!empty($organization)) {
177 foreach (
Utils::xpQuery(
$xml,
'./saml_metadata:AdditionalMetadataLocation') as $aml) {
188 public function toXML(\
DOMElement $parent = null)
190 assert(is_string($this->entityID));
191 assert(is_null($this->ID) || is_string($this->ID));
192 assert(is_null($this->validUntil) || is_int($this->validUntil));
193 assert(is_null($this->cacheDuration) || is_string($this->cacheDuration));
201 if ($parent === null) {
204 $doc->appendChild($e);
206 $e = $parent->ownerDocument->createElementNS(
Constants::NS_MD,
'md:EntityDescriptor');
207 $parent->appendChild($e);
210 $e->setAttribute(
'entityID', $this->entityID);
212 if (isset($this->ID)) {
213 $e->setAttribute(
'ID', $this->ID);
216 if (isset($this->validUntil)) {
217 $e->setAttribute(
'validUntil', gmdate(
'Y-m-d\TH:i:s\Z', $this->validUntil));
220 if (isset($this->cacheDuration)) {
221 $e->setAttribute(
'cacheDuration', $this->cacheDuration);
231 if (isset($this->AffiliationDescriptor)) {
232 $this->AffiliationDescriptor->toXML($e);
235 if (isset($this->Organization)) {
236 $this->Organization->toXML($e);
$AdditionalMetadataLocation
__construct(\DOMElement $xml=null)
Initialize an EntitiyDescriptor.
const NS_MD
The namespace for the SAML 2 metadata.
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
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...
static addList(\DOMElement $parent, array $extensions)
Add a list of Extensions to the given element.
static getList(\DOMElement $parent)
Get a list of Extensions in the given element.