simplesamlphp /
xml-common
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace SimpleSAML\XMLSchema\XML; |
||
| 6 | |||
| 7 | use DOMElement; |
||
| 8 | use SimpleSAML\XML\Assert\Assert; |
||
| 9 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||
| 10 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
| 11 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 12 | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
||
| 13 | use SimpleSAML\XMLSchema\Type\IDValue; |
||
| 14 | use SimpleSAML\XMLSchema\Type\NCNameValue; |
||
| 15 | use SimpleSAML\XMLSchema\XML\Interface\IdentityConstraintInterface; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class representing the key-element. |
||
| 19 | * |
||
| 20 | * @package simplesamlphp/xml-common |
||
| 21 | */ |
||
| 22 | final class Key extends AbstractKeybase implements IdentityConstraintInterface, SchemaValidatableElementInterface |
||
| 23 | { |
||
| 24 | use SchemaValidatableElementTrait; |
||
| 25 | |||
| 26 | |||
| 27 | public const string LOCALNAME = 'key'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Key constructor |
||
| 32 | * |
||
| 33 | * @param \SimpleSAML\XMLSchema\Type\NCNameValue $name |
||
| 34 | * @param \SimpleSAML\XMLSchema\XML\Selector $selector |
||
| 35 | * @param array<\SimpleSAML\XMLSchema\XML\Field> $field |
||
| 36 | * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation |
||
| 37 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id |
||
| 38 | * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
||
| 39 | */ |
||
| 40 | public function __construct( |
||
| 41 | NCNameValue $name, |
||
| 42 | Selector $selector, |
||
| 43 | array $field = [], |
||
| 44 | ?Annotation $annotation = null, |
||
| 45 | ?IDValue $id = null, |
||
| 46 | array $namespacedAttributes = [], |
||
| 47 | ) { |
||
| 48 | parent::__construct($name, $selector, $field, $annotation, $id, $namespacedAttributes); |
||
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * Create an instance of this object from its XML representation. |
||
| 54 | * |
||
| 55 | * @param \DOMElement $xml |
||
| 56 | * @return static |
||
| 57 | * |
||
| 58 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 59 | * if the qualified name of the supplied element is wrong |
||
| 60 | */ |
||
| 61 | public static function fromXML(DOMElement $xml): static |
||
| 62 | { |
||
| 63 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 64 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 65 | |||
| 66 | $annotation = Annotation::getChildrenOfClass($xml); |
||
| 67 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
| 68 | |||
| 69 | $selector = Selector::getChildrenOfClass($xml); |
||
| 70 | Assert::maxCount($selector, 1, TooManyElementsException::class); |
||
| 71 | |||
| 72 | $field = Field::getChildrenOfClass($xml); |
||
| 73 | |||
| 74 | return new static( |
||
| 75 | self::getAttribute($xml, 'name', NCNameValue::class), |
||
| 76 | $selector[0], |
||
| 77 | $field, |
||
| 78 | array_pop($annotation), |
||
| 79 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
| 80 | self::getAttributesNSFromXML($xml), |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |