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