1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace SimpleSAML\XMLSecurity\XML\dsig11; |
||
6 | |||
7 | use DOMElement; |
||
8 | use SimpleSAML\Assert\Assert; |
||
9 | use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
||
10 | use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; |
||
11 | |||
12 | use function array_pop; |
||
13 | |||
14 | /** |
||
15 | * Class representing a dsig11:PnB element. |
||
16 | * |
||
17 | * @package simplesaml/xml-security |
||
18 | */ |
||
19 | final class PnB extends AbstractPnBFieldParamsType implements SchemaValidatableElementInterface |
||
20 | { |
||
21 | use SchemaValidatableElementTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
22 | |||
23 | /** |
||
24 | * Convert XML into a PnB element |
||
25 | * |
||
26 | * @param \DOMElement $xml The XML element we should load |
||
27 | * @return static |
||
28 | * |
||
29 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
30 | * If the qualified name of the supplied element is wrong |
||
31 | */ |
||
32 | public static function fromXML(DOMElement $xml): static |
||
33 | { |
||
34 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
35 | Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
||
36 | |||
37 | $k1 = K1::getChildrenOfClass($xml); |
||
38 | Assert::minCount($k1, 1, MissingElementException::class); |
||
39 | Assert::maxCount($k1, 1, TooManyElementsException::class); |
||
40 | |||
41 | $k2 = K2::getChildrenOfClass($xml); |
||
42 | Assert::minCount($k2, 1, MissingElementException::class); |
||
43 | Assert::maxCount($k2, 1, TooManyElementsException::class); |
||
44 | |||
45 | $k3 = K3::getChildrenOfClass($xml); |
||
46 | Assert::minCount($k3, 1, MissingElementException::class); |
||
47 | Assert::maxCount($k3, 1, TooManyElementsException::class); |
||
48 | |||
49 | $m = M::getChildrenOfClass($xml); |
||
50 | Assert::minCount($m, 1, MissingElementException::class); |
||
51 | Assert::maxCount($m, 1, TooManyElementsException::class); |
||
52 | |||
53 | return new static( |
||
54 | array_pop($m), |
||
55 | array_pop($k1), |
||
56 | array_pop($k2), |
||
57 | array_pop($k3), |
||
58 | ); |
||
59 | } |
||
60 | } |
||
61 |