Issues (10)

src/Chunks/EidasRequestedAttributes.php (1 issue)

1
<?php
2
3
namespace OMSAML2\Chunks;
4
5
use DOMElement;
6
use SAML2\XML\Chunk;
7
8
class EidasRequestedAttributes extends Chunk
9
{
10
11
    const NS_EIDAS = 'http://eidas.europa.eu/saml-extensions';
12
    const LOCAL_NAME = 'RequestedAttributes';
13
    const QUALIFIED_NAME = 'eidas:' . self::LOCAL_NAME;
14
    /**@var $requested_attributes EidasRequestedAttribute[] */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $requested_attributes at position 0 could not be parsed: Unknown type name '$requested_attributes' at position 0 in $requested_attributes.
Loading history...
15
    public $requested_attributes = [];
16
17
    public function __construct(DOMElement $xml = null)
18
    {
19
        if (!empty($xml) && $xml->localName != self::LOCAL_NAME) {
20
            $xml = $xml->ownerDocument->getElementsByTagNameNS(self::NS_EIDAS, self::LOCAL_NAME)->item(0);
21
        }
22
        if (empty($xml)) {
23
            return;
24
        }
25
        parent::__construct($xml);
26
        foreach ($xml->getElementsByTagNameNS(self::NS_EIDAS, EidasRequestedAttribute::LOCAL_NAME) as $requestedAttr) {
27
            $this->requested_attributes[] = new EidasRequestedAttribute($requestedAttr);
28
        }
29
    }
30
31
    public function toXML(DOMElement $parent): DOMElement
32
    {
33
        $e = $parent->ownerDocument->createElementNS(self::NS_EIDAS, self::QUALIFIED_NAME);
34
        foreach ($this->requested_attributes as $attribute) {
35
            $attribute->toXML($e);
36
        }
37
        $parent->appendChild($e);
38
        return $e;
39
    }
40
}