/**
  * Initialize an EntitiesDescriptor.
  *
  * @param DOMElement|NULL $xml The XML element we should load.
  */
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct($xml);
     if ($xml === NULL) {
         return;
     }
     if ($xml->hasAttribute('ID')) {
         $this->ID = $xml->getAttribute('ID');
     }
     if ($xml->hasAttribute('validUntil')) {
         $this->validUntil = SAML2_Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
     }
     if ($xml->hasAttribute('cacheDuration')) {
         $this->cacheDuration = $xml->getAttribute('cacheDuration');
     }
     if ($xml->hasAttribute('Name')) {
         $this->Name = $xml->getAttribute('Name');
     }
     $this->Extensions = SAML2_XML_md_Extensions::getList($xml);
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
         if ($node->localName === 'EntityDescriptor') {
             $this->children[] = new SAML2_XML_md_EntityDescriptor($node);
         } else {
             $this->children[] = new SAML2_XML_md_EntitiesDescriptor($node);
         }
     }
 }
 /**
  * Initialize a AffiliationDescriptor.
  *
  * @param DOMElement|NULL $xml  The XML element we should load.
  */
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct($xml);
     if ($xml === NULL) {
         return;
     }
     if (!$xml->hasAttribute('affiliationOwnerID')) {
         throw new Exception('Missing affiliationOwnerID on AffiliationDescriptor.');
     }
     $this->affiliationOwnerID = $xml->getAttribute('affiliationOwnerID');
     if ($xml->hasAttribute('ID')) {
         $this->ID = $xml->getAttribute('ID');
     }
     if ($xml->hasAttribute('validUntil')) {
         $this->validUntil = SimpleSAML_Utilities::parseSAML2Time($xml->getAttribute('validUntil'));
     }
     if ($xml->hasAttribute('cacheDuration')) {
         $this->cacheDuration = $xml->getAttribute('cacheDuration');
     }
     $this->Extensions = SAML2_XML_md_Extensions::getList($xml);
     $this->AffiliateMember = SAML2_Utils::extractStrings($xml, './saml_metadata:AffiliateMember');
     if (empty($this->AffiliateMember)) {
         throw new Exception('Missing AffiliateMember in AffiliationDescriptor.');
     }
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) {
         $this->KeyDescriptor[] = new SAML2_XML_md_KeyDescriptor($kd);
     }
 }
 /**
  * Initialize a RoleDescriptor.
  *
  * @param string          $elementName The name of this element.
  * @param DOMElement|NULL $xml         The XML element we should load.
  * @throws Exception
  */
 protected function __construct($elementName, DOMElement $xml = NULL)
 {
     assert('is_string($elementName)');
     parent::__construct($xml);
     $this->elementName = $elementName;
     if ($xml === NULL) {
         return;
     }
     if ($xml->hasAttribute('ID')) {
         $this->ID = $xml->getAttribute('ID');
     }
     if ($xml->hasAttribute('validUntil')) {
         $this->validUntil = SAML2_Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
     }
     if ($xml->hasAttribute('cacheDuration')) {
         $this->cacheDuration = $xml->getAttribute('cacheDuration');
     }
     if (!$xml->hasAttribute('protocolSupportEnumeration')) {
         throw new Exception('Missing protocolSupportEnumeration attribute on ' . $xml->localName);
     }
     $this->protocolSupportEnumeration = preg_split('/[\\s]+/', $xml->getAttribute('protocolSupportEnumeration'));
     if ($xml->hasAttribute('errorURL')) {
         $this->errorURL = $xml->getAttribute('errorURL');
     }
     $this->Extensions = SAML2_XML_md_Extensions::getList($xml);
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) {
         $this->KeyDescriptor[] = new SAML2_XML_md_KeyDescriptor($kd);
     }
     $organization = SAML2_Utils::xpQuery($xml, './saml_metadata:Organization');
     if (count($organization) > 1) {
         throw new Exception('More than one Organization in the entity.');
     } elseif (!empty($organization)) {
         $this->Organization = new SAML2_XML_md_Organization($organization[0]);
     }
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) {
         $this->contactPersons[] = new SAML2_XML_md_ContactPerson($cp);
     }
 }
 /**
  * @param DOMElement $xml
  */
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct($xml);
 }
 /**
  * Initialize an EntitiyDescriptor.
  *
  * @param DOMElement|NULL $xml The XML element we should load.
  * @throws Exception
  */
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct($xml);
     if ($xml === NULL) {
         return;
     }
     if (!$xml->hasAttribute('entityID')) {
         throw new Exception('Missing required attribute entityID on EntityDescriptor.');
     }
     $this->entityID = $xml->getAttribute('entityID');
     if ($xml->hasAttribute('ID')) {
         $this->ID = $xml->getAttribute('ID');
     }
     if ($xml->hasAttribute('validUntil')) {
         $this->validUntil = SAML2_Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
     }
     if ($xml->hasAttribute('cacheDuration')) {
         $this->cacheDuration = $xml->getAttribute('cacheDuration');
     }
     $this->Extensions = SAML2_XML_md_Extensions::getList($xml);
     for ($node = $xml->firstChild; $node !== NULL; $node = $node->nextSibling) {
         if (!$node instanceof DOMElement) {
             continue;
         }
         if ($node->namespaceURI !== SAML2_Const::NS_MD) {
             continue;
         }
         switch ($node->localName) {
             case 'RoleDescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_UnknownRoleDescriptor($node);
                 break;
             case 'IDPSSODescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_IDPSSODescriptor($node);
                 break;
             case 'SPSSODescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_SPSSODescriptor($node);
                 break;
             case 'AuthnAuthorityDescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_AuthnAuthorityDescriptor($node);
                 break;
             case 'AttributeAuthorityDescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_AttributeAuthorityDescriptor($node);
                 break;
             case 'PDPDescriptor':
                 $this->RoleDescriptor[] = new SAML2_XML_md_PDPDescriptor($node);
                 break;
         }
     }
     $affiliationDescriptor = SAML2_Utils::xpQuery($xml, './saml_metadata:AffiliationDescriptor');
     if (count($affiliationDescriptor) > 1) {
         throw new Exception('More than one AffiliationDescriptor in the entity.');
     } elseif (!empty($affiliationDescriptor)) {
         $this->AffiliationDescriptor = new SAML2_XML_md_AffiliationDescriptor($affiliationDescriptor[0]);
     }
     if (empty($this->RoleDescriptor) && is_null($this->AffiliationDescriptor)) {
         throw new Exception('Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.');
     } elseif (!empty($this->RoleDescriptor) && !is_null($this->AffiliationDescriptor)) {
         throw new Exception('AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.');
     }
     $organization = SAML2_Utils::xpQuery($xml, './saml_metadata:Organization');
     if (count($organization) > 1) {
         throw new Exception('More than one Organization in the entity.');
     } elseif (!empty($organization)) {
         $this->Organization = new SAML2_XML_md_Organization($organization[0]);
     }
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) {
         $this->ContactPerson[] = new SAML2_XML_md_ContactPerson($cp);
     }
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:AdditionalMetadataLocation') as $aml) {
         $this->AdditionalMetadataLocation[] = new SAML2_XML_md_AdditionalMetadataLocation($aml);
     }
 }