Completed
Push — master ( 4e360d...80bc96 )
by Daan van
07:27
created

ArtifactResponse::getAny()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SAML2;
4
5
/**
6
 * The \SAML2\ArtifactResponse, is the response to the \SAML2\ArtifactResolve.
7
 *
8
 * @author Danny Bollaert, UGent AS. <[email protected]>
9
 * @package SimpleSAMLphp
10
 */
11
class ArtifactResponse extends StatusResponse
12
{
13
    /**
14
     * The \DOMElement with the message the artifact refers
15
     * to, or null if we don't refer to any artifact.
16
     *
17
     * @var \DOMElement|null
18
     */
19
    private $any;
20
21
22
    public function __construct(\DOMElement $xml = null)
23
    {
24
        parent::__construct('ArtifactResponse', $xml);
25
26
        if (!is_null($xml)) {
27
            $status = Utils::xpQuery($xml, './saml_protocol:Status');
28
            assert('!empty($status)'); /* Will have failed during StatusResponse parsing. */
29
30
            $status = $status[0];
31
32
            for ($any = $status->nextSibling; $any !== null; $any = $any->nextSibling) {
33
                if ($any instanceof \DOMElement) {
34
                    $this->any = $any;
35
                    break;
36
                }
37
                /* Ignore comments and text nodes. */
38
            }
39
        }
40
    }
41
42
    public function setAny(\DOMElement $any = null)
43
    {
44
        $this->any = $any;
45
    }
46
47
    public function getAny()
48
    {
49
        return $this->any;
50
    }
51
52
    /**
53
     * Convert the response message to an XML element.
54
     *
55
     * @return \DOMElement This response.
56
     */
57
    public function toUnsignedXML()
58
    {
59
        $root = parent::toUnsignedXML();
60
        if (isset($this->any)) {
61
            $node = $root->ownerDocument->importNode($this->any, true);
62
            $root->appendChild($node);
63
        }
64
65
        return $root;
66
    }
67
}
68