simplesamlphp /
xml-security
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace SimpleSAML\XMLSecurity\XML\xenc; |
||
| 6 | |||
| 7 | use DOMElement; |
||
| 8 | use SimpleSAML\Assert\Assert; |
||
| 9 | use SimpleSAML\XML\ExtendableElementTrait; |
||
| 10 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 11 | use SimpleSAML\XMLSchema\Type\AnyURIValue; |
||
| 12 | use SimpleSAML\XMLSchema\XML\Constants\NS; |
||
| 13 | |||
| 14 | use function strval; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Abstract class representing references. No custom elements are allowed. |
||
| 18 | * |
||
| 19 | * @package simplesamlphp/xml-security |
||
| 20 | */ |
||
| 21 | abstract class AbstractReference extends AbstractXencElement |
||
| 22 | { |
||
| 23 | use ExtendableElementTrait; |
||
| 24 | |||
| 25 | |||
| 26 | /** The namespace-attribute for the xs:any element */ |
||
| 27 | public const string XS_ANY_ELT_NAMESPACE = NS::OTHER; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * AbstractReference constructor. |
||
| 32 | * |
||
| 33 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $uri |
||
| 34 | * @param \SimpleSAML\XML\SerializableElementInterface[] $elements |
||
| 35 | */ |
||
| 36 | final public function __construct( |
||
| 37 | protected AnyURIValue $uri, |
||
| 38 | array $elements = [], |
||
| 39 | ) { |
||
| 40 | $this->setElements($elements); |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * Get the value of the URI attribute of this reference. |
||
| 46 | * |
||
| 47 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue |
||
| 48 | */ |
||
| 49 | public function getURI(): AnyURIValue |
||
| 50 | { |
||
| 51 | return $this->uri; |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * @inheritDoc |
||
| 57 | * |
||
| 58 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 59 | * if the qualified name of the supplied element is wrong |
||
| 60 | * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException |
||
| 61 | * if the supplied element is missing one of the mandatory attributes |
||
| 62 | */ |
||
| 63 | public static function fromXML(DOMElement $xml): static |
||
| 64 | { |
||
| 65 | Assert::same($xml->localName, static::getClassName(static::class), InvalidDOMElementException::class); |
||
| 66 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 67 | |||
| 68 | return new static( |
||
| 69 | self::getAttribute($xml, 'URI', AnyURIValue::class), |
||
| 70 | self::getChildElementsFromXML($xml), |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritDoc |
||
| 77 | */ |
||
| 78 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 79 | { |
||
| 80 | $e = $this->instantiateParentElement($parent); |
||
| 81 | $e->setAttribute('URI', strval($this->getUri())); |
||
| 82 | |||
| 83 | foreach ($this->getElements() as $elt) { |
||
| 84 | $elt->toXML($e); |
||
| 85 | } |
||
| 86 | |||
| 87 | return $e; |
||
| 88 | } |
||
| 89 | } |
||
| 90 |