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\AnyURIValue; |
||
| 14 | use SimpleSAML\XMLSchema\Type\IDValue; |
||
| 15 | |||
| 16 | use function strval; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Class representing the include-element. |
||
| 20 | * |
||
| 21 | * @package simplesamlphp/xml-common |
||
| 22 | */ |
||
| 23 | final class XsInclude extends AbstractAnnotated implements SchemaValidatableElementInterface |
||
| 24 | { |
||
| 25 | use SchemaValidatableElementTrait; |
||
| 26 | |||
| 27 | |||
| 28 | public const string LOCALNAME = 'include'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * Include constructor |
||
| 33 | * |
||
| 34 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $schemaLocation |
||
| 35 | * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation |
||
| 36 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id |
||
| 37 | * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
||
| 38 | */ |
||
| 39 | public function __construct( |
||
| 40 | protected AnyURIValue $schemaLocation, |
||
| 41 | ?Annotation $annotation = null, |
||
| 42 | ?IDValue $id = null, |
||
| 43 | array $namespacedAttributes = [], |
||
| 44 | ) { |
||
| 45 | parent::__construct($annotation, $id, $namespacedAttributes); |
||
| 46 | } |
||
| 47 | |||
| 48 | |||
| 49 | /** |
||
| 50 | * Collect the value of the schemaLocation-property |
||
| 51 | * |
||
| 52 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue |
||
| 53 | */ |
||
| 54 | public function getSchemaLocation(): AnyURIValue |
||
| 55 | { |
||
| 56 | return $this->schemaLocation; |
||
| 57 | } |
||
| 58 | |||
| 59 | |||
| 60 | /** |
||
| 61 | * Add this Import to an XML element. |
||
| 62 | * |
||
| 63 | * @param \DOMElement|null $parent The element we should append this import to. |
||
| 64 | * @return \DOMElement |
||
| 65 | */ |
||
| 66 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 67 | { |
||
| 68 | $e = parent::toXML($parent); |
||
| 69 | $e->setAttribute('schemaLocation', strval($this->getSchemaLocation())); |
||
| 70 | |||
| 71 | return $e; |
||
| 72 | } |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * Create an instance of this object from its XML representation. |
||
| 77 | * |
||
| 78 | * @param \DOMElement $xml |
||
| 79 | * @return static |
||
| 80 | * |
||
| 81 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 82 | * if the qualified name of the supplied element is wrong |
||
| 83 | */ |
||
| 84 | public static function fromXML(DOMElement $xml): static |
||
| 85 | { |
||
| 86 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 87 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 88 | |||
| 89 | $annotation = Annotation::getChildrenOfClass($xml); |
||
| 90 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
| 91 | |||
| 92 | return new static( |
||
| 93 | self::getAttribute($xml, 'schemaLocation', AnyURIValue::class), |
||
| 94 | array_pop($annotation), |
||
| 95 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
| 96 | self::getAttributesNSFromXML($xml), |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 |