Issues (81)

src/XML/dsig11/KeyInfoReference.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
9
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException};
10
use SimpleSAML\XMLSchema\Type\{AnyURIValue, IDValue};
11
use SimpleSAML\XMLSecurity\Assert\Assert;
12
13
/**
14
 * Class representing a dsig11:KeyInfoReference element.
15
 *
16
 * @package simplesamlphp/xml-security
17
 */
18
final class KeyInfoReference extends AbstractDsig11Element implements SchemaValidatableElementInterface
19
{
20
    use SchemaValidatableElementTrait;
0 ignored issues
show
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\dsig11\KeyInfoReference: $message, $line
Loading history...
21
22
    /**
23
     * Initialize a KeyInfoReference element.
24
     *
25
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $URI
26
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
27
     */
28
    public function __construct(
29
        protected AnyURIValue $URI,
30
        protected ?IDValue $Id = null,
31
    ) {
32
    }
33
34
35
    /**
36
     * Collect the value of the URI-property
37
     *
38
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
39
     */
40
    public function getURI(): AnyURIValue
41
    {
42
        return $this->URI;
43
    }
44
45
46
    /**
47
     * Collect the value of the Id-property
48
     *
49
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
50
     */
51
    public function getId(): ?IDValue
52
    {
53
        return $this->Id;
54
    }
55
56
57
    /**
58
     * Convert XML into a KeyInfoReference
59
     *
60
     * @param \DOMElement $xml The XML element we should load
61
     * @return static
62
     *
63
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
64
     *   If the qualified name of the supplied element is wrong
65
     */
66
    public static function fromXML(DOMElement $xml): static
67
    {
68
        Assert::same($xml->localName, 'KeyInfoReference', InvalidDOMElementException::class);
69
        Assert::same($xml->namespaceURI, KeyInfoReference::NS, InvalidDOMElementException::class);
70
71
        return new static(
72
            KeyInfoReference::getAttribute($xml, 'URI', AnyURIValue::class),
73
            KeyInfoReference::getOptionalAttribute($xml, 'Id', IDValue::class, null),
74
        );
75
    }
76
77
78
    /**
79
     * Convert this KeyInfoReference element to XML.
80
     *
81
     * @param \DOMElement|null $parent The element we should append this KeyInfoReference element to.
82
     * @return \DOMElement
83
     */
84
    public function toXML(?DOMElement $parent = null): DOMElement
85
    {
86
        $e = $this->instantiateParentElement($parent);
87
        $e->setAttribute('URI', strval($this->getURI()));
88
89
        if ($this->getId() !== null) {
90
            $e->setAttribute('Id', strval($this->getId()));
91
        }
92
93
        return $e;
94
    }
95
}
96