Issues (81)

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

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