SAML2\Message::__construct PHP Method

__construct() protected method

This constructor takes an optional parameter with a \DOMElement. If this parameter is given, the message will be initialized with data from that XML element. If no XML element is given, the message is initialized with suitable default values.
protected __construct ( string $tagName, DOMElement $xml = null )
$tagName string The tag name of the root element
$xml DOMElement The input message
    protected function __construct($tagName, \DOMElement $xml = null)
    {
        assert('is_string($tagName)');
        $this->tagName = $tagName;
        $this->id = Utils::getContainer()->generateId();
        $this->issueInstant = Temporal::getTime();
        $this->certificates = array();
        $this->validators = array();
        if ($xml === null) {
            return;
        }
        if (!$xml->hasAttribute('ID')) {
            throw new \Exception('Missing ID attribute on SAML message.');
        }
        $this->id = $xml->getAttribute('ID');
        if ($xml->getAttribute('Version') !== '2.0') {
            /* Currently a very strict check. */
            throw new \Exception('Unsupported version: ' . $xml->getAttribute('Version'));
        }
        $this->issueInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('IssueInstant'));
        if ($xml->hasAttribute('Destination')) {
            $this->destination = $xml->getAttribute('Destination');
        }
        if ($xml->hasAttribute('Consent')) {
            $this->consent = $xml->getAttribute('Consent');
        }
        $issuer = Utils::xpQuery($xml, './saml_assertion:Issuer');
        if (!empty($issuer)) {
            $this->issuer = new XML\saml\Issuer($issuer[0]);
            if ($this->issuer->Format === Constants::NAMEID_ENTITY) {
                $this->issuer = $this->issuer->value;
            }
        }
        $this->validateSignature($xml);
        $this->extensions = Extensions::getList($xml);
    }