1<?php 2 3namespace SAML2\XML\ecp; 4 5use DOMElement; 6use InvalidArgumentException; 7 8use SAML2\Constants; 9 10/** 11 * Class representing the ECP Response element. 12 */ 13class 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