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\XMLSchema\Exception\InvalidDOMElementException; |
||
| 10 | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
||
| 11 | use SimpleSAML\XMLSchema\Type\IDValue; |
||
| 12 | use SimpleSAML\XMLSchema\Type\QNameValue; |
||
| 13 | |||
| 14 | use function array_merge; |
||
| 15 | use function array_pop; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class representing the local version of xs:extension. |
||
| 19 | * |
||
| 20 | * @package simplesamlphp/xml-common |
||
| 21 | */ |
||
| 22 | final class Extension extends AbstractExtensionType |
||
| 23 | { |
||
| 24 | public const string LOCALNAME = 'extension'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * Create an instance of this object from its XML representation. |
||
| 29 | * |
||
| 30 | * @param \DOMElement $xml |
||
| 31 | * @return static |
||
| 32 | * |
||
| 33 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 34 | * if the qualified name of the supplied element is wrong |
||
| 35 | */ |
||
| 36 | public static function fromXML(DOMElement $xml): static |
||
| 37 | { |
||
| 38 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 39 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 40 | |||
| 41 | $annotation = Annotation::getChildrenOfClass($xml); |
||
| 42 | Assert::maxCount($annotation, 1, TooManyElementsException::class); |
||
| 43 | |||
| 44 | $referencedGroup = ReferencedGroup::getChildrenOfClass($xml); |
||
| 45 | Assert::maxCount($referencedGroup, 1, TooManyElementsException::class); |
||
| 46 | |||
| 47 | $all = All::getChildrenOfClass($xml); |
||
| 48 | Assert::maxCount($all, 1, TooManyElementsException::class); |
||
| 49 | |||
| 50 | $choice = Choice::getChildrenOfClass($xml); |
||
| 51 | Assert::maxCount($choice, 1, TooManyElementsException::class); |
||
| 52 | |||
| 53 | $sequence = Sequence::getChildrenOfClass($xml); |
||
| 54 | Assert::maxCount($sequence, 1, TooManyElementsException::class); |
||
| 55 | |||
| 56 | $particles = array_merge($referencedGroup, $all, $choice, $sequence); |
||
| 57 | Assert::maxCount($particles, 1, TooManyElementsException::class); |
||
| 58 | |||
| 59 | $localAttribute = LocalAttribute::getChildrenOfClass($xml); |
||
| 60 | $attributeGroup = ReferencedAttributeGroup::getChildrenOfClass($xml); |
||
| 61 | $attributes = array_merge($localAttribute, $attributeGroup); |
||
| 62 | |||
| 63 | $anyAttribute = AnyAttribute::getChildrenOfClass($xml); |
||
| 64 | Assert::maxCount($anyAttribute, 1, TooManyElementsException::class); |
||
| 65 | |||
| 66 | return new static( |
||
| 67 | self::getAttribute($xml, 'base', QNameValue::class), |
||
| 68 | array_pop($particles), |
||
| 69 | $attributes, |
||
| 70 | array_pop($anyAttribute), |
||
| 71 | array_pop($annotation), |
||
| 72 | self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
||
| 73 | self::getAttributesNSFromXML($xml), |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |