1<?php
2
3declare(strict_types=1);
4
5namespace SAML2;
6
7use DOMElement;
8
9/**
10 * The Artifact is part of the SAML 2.0 IdP code, and it builds an artifact object.
11 * I am using strings, because I find them easier to work with.
12 * I want to use this, to be consistent with the other saml2_requests
13 *
14 * @author Danny Bollaert, UGent AS. <danny.bollaert@ugent.be>
15 * @package SimpleSAMLphp
16 */
17class ArtifactResolve extends Request
18{
19    /** @var string */
20    private $artifact;
21
22
23    /**
24     * Constructor for SAML 2 ArtifactResolve.
25     *
26     * @param \DOMElement|null $xml The input assertion.
27     */
28    public function __construct(DOMElement $xml = null)
29    {
30        parent::__construct('ArtifactResolve', $xml);
31
32        if (!is_null($xml)) {
33            $results = Utils::xpQuery($xml, './saml_protocol:Artifact');
34            $this->artifact = $results[0]->textContent;
35        }
36    }
37
38    /**
39     * Retrieve the Artifact in this response.
40     *
41     * @return string artifact.
42     */
43    public function getArtifact() : string
44    {
45        return $this->artifact;
46    }
47
48
49    /**
50     * Set the artifact that should be included in this response.
51     *
52     * @param string $artifact
53     * @return void
54     */
55    public function setArtifact(string $artifact) : void
56    {
57        $this->artifact = $artifact;
58    }
59
60
61    /**
62     * Convert the response message to an XML element.
63     *
64     * @return \DOMElement This response.
65     */
66    public function toUnsignedXML() : DOMElement
67    {
68        $root = parent::toUnsignedXML();
69        $artifactelement = $this->document->createElementNS(Constants::NS_SAMLP, 'Artifact', $this->artifact);
70        $root->appendChild($artifactelement);
71
72        return $root;
73    }
74}
75