Completed
Push — master ( a0de91...6ebd4b )
by Thijs
06:42 queued 04:11
created

Response   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 26 7
A toXML() 0 17 2
1
<?php
2
3
namespace SAML2\XML\ecp;
4
5
use DOMElement;
6
use InvalidArgumentException;
7
8
use SAML2\Constants;
9
10
/**
11
 * Class representing the ECP Response element.
12
 */
13
class Response
14
{
15
    /**
16
     * The AssertionConsumerServiceURL.
17
     *
18
     * @var string
19
     */
20
    public $AssertionConsumerServiceURL;
21
22
    /**
23
     * Create a ECP Response element.
24
     *
25
     * @param DOMElement|null $xml The XML element we should load.
26
     */
27
    public function __construct(DOMElement $xml = null)
28
    {
29
        if ($xml === null) {
30
            return;
31
        }
32
33
        if (!$xml->hasAttributeNS(Constants::NS_SOAP, 'mustUnderstand')) {
34
            throw new Exception('Missing SOAP-ENV:mustUnderstand attribute in <ecp:Response>.');
35
        }
36
        if ($xml->getAttributeNS(Constants::NS_SOAP, 'mustUnderstand') !== '1') {
37
            throw new Exception('Invalid value of SOAP-ENV:mustUnderstand attribute in <ecp:Response>.');
38
        }
39
40
        if (!$xml->hasAttributeNS(Constants::NS_SOAP, 'actor')) {
41
            throw new Exception('Missing SOAP-ENV:actor attribute in <ecp:Response>.');
42
        }
43
        if ($xml->getAttributeNS(Constants::NS_SOAP, 'actor') !== 'http://schemas.xmlsoap.org/soap/actor/next') {
44
            throw new Exception('Invalid value of SOAP-ENV:actor attribute in <ecp:Response>.');
45
        }
46
47
        if (!$xml->hasAttribute('AssertionConsumerServiceURL')) {
48
            throw new Exception('Missing AssertionConsumerServiceURL attribute in <ecp:Response>.');
49
        }
50
51
        $this->AssertionConsumerServiceURL = $xml->getAttribute('AssertionConsumerServiceURL');
52
    }
53
    /**
54
     * Convert this ECP Response to XML.
55
     *
56
     * @param DOMElement $parent The element we should append this element to.
57
     */
58
    public function toXML(DOMElement $parent)
59
    {
60
        if (!is_string($this->AssertionConsumerServiceURL)) {
61
            throw new InvalidArgumentException("AssertionConsumerServiceURL must be a string");
62
        }
63
64
        $doc = $parent->ownerDocument;
65
        $response = $doc->createElementNS(Constants::NS_ECP, 'ecp:Response');
66
67
        $parent->appendChild($response);
68
69
        $response->setAttributeNS(Constants::NS_SOAP, 'SOAP-ENV:mustUnderstand', '1');
70
        $response->setAttributeNS(Constants::NS_SOAP, 'SOAP-ENV:actor', 'http://schemas.xmlsoap.org/soap/actor/next');
71
        $response->setAttribute('AssertionConsumerServiceURL', $this->AssertionConsumerServiceURL);
72
73
        return $response;
74
    }
75
}
76