1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OMSAML2\Chunks; |
4
|
|
|
|
5
|
|
|
use DOMElement; |
6
|
|
|
use SAML2\XML\Chunk; |
7
|
|
|
|
8
|
|
|
class EidasRequestedAttribute extends Chunk |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
const NAME_FORMAT_URI = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'; |
12
|
|
|
const NS_EIDAS = 'http://eidas.europa.eu/saml-extensions'; |
13
|
|
|
const LOCAL_NAME = 'RequestedAttribute'; |
14
|
|
|
|
15
|
|
|
public $Name = null; |
16
|
|
|
public $isRequired = false; |
17
|
|
|
public $NameFormat = self::NAME_FORMAT_URI; |
18
|
|
|
public $NodeValue = null; |
19
|
|
|
|
20
|
|
|
public function __construct(?DOMElement $xml = null) |
21
|
|
|
{ |
22
|
|
|
if (empty($xml)) { |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
parent::__construct($xml); |
26
|
|
|
$this->Name = $xml->attributes->getNamedItem('Name')->nodeValue; |
27
|
|
|
$isRequired = $xml->attributes->getNamedItem('isRequired'); |
28
|
|
|
$this->isRequired = empty($isRequired) ? false : $isRequired->nodeValue; |
29
|
|
|
$NameFormat = $xml->attributes->getNamedItem('NameFormat'); |
30
|
|
|
$this->NameFormat = empty($NameFormat) ? self::NAME_FORMAT_URI : $NameFormat->nodeValue; |
31
|
|
|
$NodeValue = $xml->getElementsByTagNameNS(self::NS_EIDAS, 'AttributeValue')->item(0); |
32
|
|
|
$this->NodeValue = empty($NodeValue) ? null : $NodeValue->nodeValue; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function toXML(DOMElement $parent): DOMElement |
36
|
|
|
{ |
37
|
|
|
$e = $parent->ownerDocument->createElementNS(self::NS_EIDAS, self::LOCAL_NAME); |
38
|
|
|
$e->setAttribute('Name', $this->Name); |
39
|
|
|
$e->setAttribute('NameFormat', $this->NameFormat); |
40
|
|
|
$e->setAttribute('isRequired', $this->isRequired); |
41
|
|
|
if ($this->NodeValue != null) { |
42
|
|
|
$val = $e->ownerDocument->createElementNS(self::NS_EIDAS, 'AttributeValue'); |
43
|
|
|
$val->nodeValue = var_export($this->NodeValue, true); |
44
|
|
|
$e->appendChild($val); |
45
|
|
|
} |
46
|
|
|
$parent->appendChild($e); |
47
|
|
|
return $e; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
} |