55namespace SimpleSAML \SAML2 \XML ;
66
77use DOMElement ;
8- use SimpleSAML \SAML2 \Assert \Assert ;
9- use SimpleSAML \SAML2 \Constants as C ;
10- use SimpleSAML \SAML2 \Exception \ProtocolViolationException ;
11- use SimpleSAML \XML \ElementInterface ;
12-
13- use function in_array ;
8+ use SimpleSAML \XML \ExtendableElementTrait ;
149
1510/**
1611 * Trait grouping common functionality for elements implementing ExtensionType.
1914 */
2015trait ExtensionsTrait
2116{
22- /** @var \SimpleSAML\XML\SerializableElementInterface[] */
23- protected array $ extensions = [];
17+ use ExtendableElementTrait;
2418
2519
2620 /**
@@ -30,52 +24,19 @@ trait ExtensionsTrait
3024 */
3125 public function __construct (array $ extensions )
3226 {
33- Assert::maxCount ($ extensions , C::UNBOUNDED_LIMIT );
34- Assert::allIsInstanceOf ($ extensions , ElementInterface::class);
35-
36- foreach ($ extensions as $ extension ) {
37- /** @var \SimpleSAML\XML\AbstractElement $extension */
38- $ namespace = $ extension ->getNamespaceURI ();
39-
40- Assert::notNull (
41- $ namespace ,
42- 'Extensions MUST NOT include global (non-namespace-qualified) elements. ' ,
43- ProtocolViolationException::class,
44- );
45- Assert::true (
46- !in_array ($ namespace , [C::NS_SAML , C::NS_SAMLP ], true ),
47- 'Extensions MUST NOT include any SAML-defined namespace elements. ' ,
48- ProtocolViolationException::class,
49- );
50- }
51-
52- /**
53- * Set an array with all extensions present.
54- */
55- $ this ->extensions = $ extensions ;
56- }
57-
58-
59- /**
60- * Get an array with all extensions present.
61- *
62- * @return \SimpleSAML\XML\SerializableElementInterface[]
63- */
64- public function getList (): array
65- {
66- return $ this ->extensions ;
27+ $ this ->setElements ($ extensions );
6728 }
6829
6930
7031 /**
7132 */
7233 public function isEmptyElement (): bool
7334 {
74- if (empty ($ this ->getList ())) {
35+ if (empty ($ this ->getElements ())) {
7536 return true ;
7637 }
7738
78- foreach ($ this ->getList () as $ extension ) {
39+ foreach ($ this ->getElements () as $ extension ) {
7940 if ($ extension ->isEmptyElement () === false ) {
8041 return false ;
8142 }
@@ -96,7 +57,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
9657 $ e = $ this ->instantiateParentElement ($ parent );
9758
9859 if (!$ this ->isEmptyElement ()) {
99- foreach ($ this ->getList () as $ extension ) {
60+ foreach ($ this ->getElements () as $ extension ) {
10061 if (!$ extension ->isEmptyElement ()) {
10162 $ extension ->toXML ($ e );
10263 }
0 commit comments