Issues (311)

src/XML/xenc11/Parameters.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\XML\Constants\NS;
13
14
/**
15
 * Class representing xenc11:Parameters
16
 *
17
 * @package simplesamlphp/xml-security
18
 */
19
final class Parameters extends AbstractXenc11Element
20
{
21
    use ExtendableAttributesTrait;
22
    use ExtendableElementTrait;
23
24
25
    /** The namespace-attribute for the xs:any element */
26
    public const string XS_ANY_ELT_NAMESPACE = NS::ANY;
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 26 at column 24
Loading history...
27
28
    /** The namespace-attribute for the xs:anyAttribute element */
29
    public const string XS_ANY_ATTR_NAMESPACE = NS::ANY;
30
31
32
    /**
33
     * Initialize a Parameters element.
34
     *
35
     * @param array<\SimpleSAML\XML\SerializableElementInterface> $elements
36
     * @param array<\SimpleSAML\XML\Attribute> $attributes
37
     */
38
    public function __construct(array $elements = [], array $attributes = [])
39
    {
40
        $this->setElements($elements);
41
        $this->setAttributesNS($attributes);
42
    }
43
44
45
    /**
46
     * Test if an object, at the state it's in, would produce an empty XML-element
47
     */
48
    public function isEmptyElement(): bool
49
    {
50
        return empty($this->getAttributesNS())
51
            && empty($this->getElements());
52
    }
53
54
55
    /**
56
     * Convert XML into a Parameters element
57
     *
58
     * @param \DOMElement $xml The XML element we should load
59
     *
60
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
61
     *   if the qualified name of the supplied element is wrong
62
     */
63
    public static function fromXML(DOMElement $xml): static
64
    {
65
        Assert::same($xml->localName, 'Parameters', InvalidDOMElementException::class);
66
        Assert::same($xml->namespaceURI, Parameters::NS, InvalidDOMElementException::class);
67
68
        return new static(
69
            self::getChildElementsFromXML($xml),
70
            self::getAttributesNSFromXML($xml),
71
        );
72
    }
73
74
75
    /**
76
     * Convert this Parameters element to XML.
77
     *
78
     * @param \DOMElement|null $parent The element we should append this Parameters to.
79
     */
80
    public function toXML(?DOMElement $parent = null): DOMElement
81
    {
82
        $e = $this->instantiateParentElement($parent);
83
84
        foreach ($this->getAttributesNS() as $attr) {
85
            $attr->toXML($e);
86
        }
87
88
        foreach ($this->getElements() as $element) {
89
            $element->toXML($e);
90
        }
91
92
        return $e;
93
    }
94
}
95