52 parent::__construct($tagName,
$xml);
54 $this->status =
array(
55 'Code' => Constants::STATUS_SUCCESS,
64 if (
$xml->hasAttribute(
'InResponseTo')) {
65 $this->inResponseTo =
$xml->getAttribute(
'InResponseTo');
68 $status = Utils::xpQuery(
$xml,
'./saml_protocol:Status');
70 throw new \Exception(
'Missing status code on response.');
74 $statusCode = Utils::xpQuery($status,
'./saml_protocol:StatusCode');
75 if (empty($statusCode)) {
76 throw new \Exception(
'Missing status code in status element.');
78 $statusCode = $statusCode[0];
80 $this->status[
'Code'] = $statusCode->getAttribute(
'Value');
82 $subCode = Utils::xpQuery($statusCode,
'./saml_protocol:StatusCode');
83 if (!empty($subCode)) {
84 $this->status[
'SubCode'] = $subCode[0]->getAttribute(
'Value');
87 $message = Utils::xpQuery($status,
'./saml_protocol:StatusMessage');
89 $this->status[
'Message'] = trim(
$message[0]->textContent);
101 assert(array_key_exists(
"Code", $this->status));
103 if ($this->status[
'Code'] === Constants::STATUS_SUCCESS) {
118 return $this->inResponseTo;
129 assert(is_string($inResponseTo) || is_null($inResponseTo));
131 $this->inResponseTo = $inResponseTo;
142 return $this->status;
153 assert(array_key_exists(
"Code", $status));
155 $this->status = $status;
156 if (!array_key_exists(
'SubCode', $status)) {
157 $this->status[
'SubCode'] = null;
159 if (!array_key_exists(
'Message', $status)) {
160 $this->status[
'Message'] = null;
172 $root = parent::toUnsignedXML();
174 if ($this->inResponseTo !== null) {
175 $root->setAttribute(
'InResponseTo', $this->inResponseTo);
178 $status = $this->document->createElementNS(Constants::NS_SAMLP,
'Status');
179 $root->appendChild($status);
181 $statusCode = $this->document->createElementNS(Constants::NS_SAMLP,
'StatusCode');
182 $statusCode->setAttribute(
'Value', $this->status[
'Code']);
183 $status->appendChild($statusCode);
185 if (!is_null($this->status[
'SubCode'])) {
186 $subStatusCode = $this->document->createElementNS(Constants::NS_SAMLP,
'StatusCode');
187 $subStatusCode->setAttribute(
'Value', $this->status[
'SubCode']);
188 $statusCode->appendChild($subStatusCode);
191 if (!is_null($this->status[
'Message'])) {
192 Utils::addString($status, Constants::NS_SAMLP,
'StatusMessage', $this->status[
'Message']);
setStatus(array $status)
Set the status code.
toUnsignedXML()
Convert status response message to an XML element.
getStatus()
Retrieve the status code.
Base class for all SAML 2 messages.
catch(Exception $e) $message
isSuccess()
Determine whether this is a successful response.
setInResponseTo($inResponseTo)
Set the ID of the request this is a response to.
Create styles array
The data for the language used.
__construct($tagName, \DOMElement $xml=null)
Constructor for SAML 2 response messages.
getInResponseTo()
Retrieve the ID of the request this is a response to.