1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace SimpleSAML\XMLSecurity\XML\ds; |
||
6 | |||
7 | use DOMElement; |
||
8 | use SimpleSAML\XML\Constants as C; |
||
9 | use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
||
10 | use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException}; |
||
11 | use SimpleSAML\XMLSchema\Type\IDValue; |
||
12 | use SimpleSAML\XMLSecurity\Assert\Assert; |
||
13 | |||
14 | use function strval; |
||
15 | |||
16 | /** |
||
17 | * Class representing a ds:SignatureProperties element. |
||
18 | * |
||
19 | * @package simplesamlphp/xml-security |
||
20 | */ |
||
21 | final class SignatureProperties extends AbstractDsElement implements SchemaValidatableElementInterface |
||
22 | { |
||
23 | use SchemaValidatableElementTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
24 | |||
25 | /** |
||
26 | * Initialize a ds:SignatureProperties |
||
27 | * |
||
28 | * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] $signatureProperty |
||
29 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id |
||
30 | */ |
||
31 | public function __construct( |
||
32 | protected array $signatureProperty, |
||
33 | protected ?IDValue $Id = null, |
||
34 | ) { |
||
35 | Assert::maxCount($signatureProperty, C::UNBOUNDED_LIMIT); |
||
36 | Assert::allIsInstanceOf($signatureProperty, SignatureProperty::class, SchemaViolationException::class); |
||
37 | } |
||
38 | |||
39 | |||
40 | /** |
||
41 | * @return \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] |
||
42 | */ |
||
43 | public function getSignatureProperty(): array |
||
44 | { |
||
45 | return $this->signatureProperty; |
||
46 | } |
||
47 | |||
48 | |||
49 | /** |
||
50 | * @return \SimpleSAML\XMLSchema\Type\IDValue|null |
||
51 | */ |
||
52 | public function getId(): ?IDValue |
||
53 | { |
||
54 | return $this->Id; |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Convert XML into a SignatureProperties element |
||
60 | * |
||
61 | * @param \DOMElement $xml The XML element we should load |
||
62 | * @return static |
||
63 | * |
||
64 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
65 | * If the qualified name of the supplied element is wrong |
||
66 | */ |
||
67 | public static function fromXML(DOMElement $xml): static |
||
68 | { |
||
69 | Assert::same($xml->localName, 'SignatureProperties', InvalidDOMElementException::class); |
||
70 | Assert::same($xml->namespaceURI, SignatureProperties::NS, InvalidDOMElementException::class); |
||
71 | |||
72 | $signatureProperty = SignatureProperty::getChildrenOfClass($xml); |
||
73 | Assert::minCount( |
||
74 | $signatureProperty, |
||
75 | 1, |
||
76 | 'A <ds:SignatureProperties> must contain at least one <ds:SignatureProperty>.', |
||
77 | MissingElementException::class, |
||
78 | ); |
||
79 | |||
80 | return new static( |
||
81 | $signatureProperty, |
||
82 | self::getOptionalAttribute($xml, 'Id', IDValue::class, null), |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Convert this SignatureProperties element to XML. |
||
89 | * |
||
90 | * @param \DOMElement|null $parent The element we should append this SignatureProperties element to. |
||
91 | * @return \DOMElement |
||
92 | */ |
||
93 | public function toXML(?DOMElement $parent = null): DOMElement |
||
94 | { |
||
95 | $e = $this->instantiateParentElement($parent); |
||
96 | |||
97 | if ($this->getId() !== null) { |
||
98 | $e->setAttribute('Id', strval($this->getId())); |
||
99 | } |
||
100 | |||
101 | foreach ($this->getSignatureProperty() as $signatureProperty) { |
||
102 | $signatureProperty->toXML($e); |
||
103 | } |
||
104 | |||
105 | return $e; |
||
106 | } |
||
107 | } |
||
108 |