66
77use DOMElement ;
88use SimpleSAML \Assert \Assert ;
9- use SimpleSAML \XML \Chunk ;
109use SimpleSAML \XML \Exception \InvalidDOMElementException ;
10+ use SimpleSAML \XML \Chunk ;
11+ use SimpleSAML \XML \XMLElementInterface ;
12+ use SimpleSAML \XMLSecurity \XML \ds \Transforms ;
1113
1214/**
1315 * Abstract class representing references. No custom elements are allowed.
@@ -19,20 +21,20 @@ abstract class AbstractReference extends AbstractXencElement
1921 /** @var string */
2022 protected string $ uri ;
2123
22- /** @var \SimpleSAML\XML\Chunk [] */
23- protected array $ references = [] ;
24+ /** @var \SimpleSAML\XML\XMLElementInterface [] */
25+ protected array $ elements ;
2426
2527
2628 /**
2729 * AbstractReference constructor.
2830 *
2931 * @param string $uri
30- * @param \SimpleSAML\XML\Chunk [] $references
32+ * @param \SimpleSAML\XML\XMLElementInterface [] $elements
3133 */
32- protected function __construct (string $ uri , array $ references = [])
34+ protected function __construct (string $ uri , array $ elements = [])
3335 {
3436 $ this ->setURI ($ uri );
35- $ this ->setReferences ( $ references );
37+ $ this ->setElements ( $ elements );
3638 }
3739
3840
@@ -58,27 +60,27 @@ protected function setURI(string $uri): void
5860
5961
6062 /**
61- * Collect the references
63+ * Collect the embedded elements
6264 *
63- * @return \SimpleSAML\XML\Chunk []
65+ * @return \SimpleSAML\XML\XMLElementInterface []
6466 */
65- public function getReferences (): array
67+ public function getElements (): array
6668 {
67- return $ this ->references ;
69+ return $ this ->elements ;
6870 }
6971
7072
7173 /**
72- * Set the value of the references -property
74+ * Set the value of the elements -property
7375 *
74- * @param \SimpleSAML\XML\Chunk [] $references
76+ * @param \SimpleSAML\XML\XMLElementInterface [] $elements
7577 * @throws \SimpleSAML\Assert\AssertionFailedException
76- * if the supplied array contains anything other than Chunk objects
78+ * if the supplied array contains anything other than XMLElementInterface objects
7779 */
78- private function setReferences (array $ references ): void
80+ private function setElements (array $ elements ): void
7981 {
80- Assert::allIsInstanceOf ($ references , Chunk ::class);
81- $ this ->references = $ references ;
82+ Assert::allIsInstanceOf ($ elements , XMLElementInterface ::class);
83+ $ this ->elements = $ elements ;
8284 }
8385
8486
@@ -97,16 +99,18 @@ public static function fromXML(DOMElement $xml): object
9799
98100 $ URI = self ::getAttribute ($ xml , 'URI ' );
99101
100- $ references = [];
101- foreach ($ xml ->childNodes as $ reference ) {
102- if (!($ reference instanceof DOMElement)) {
102+ $ elements = [];
103+ foreach ($ xml ->childNodes as $ element ) {
104+ if (!($ element instanceof DOMElement)) {
103105 continue ;
106+ } elseif ($ element ->namespaceURI === Transforms::NS && $ element ->localName === 'Transforms ' ) {
107+ $ elements [] = new Transforms ($ element );
108+ } else {
109+ $ elements [] = new Chunk ($ element );
104110 }
105-
106- $ references [] = new Chunk ($ reference );
107111 }
108112
109- return new static ($ URI , $ references );
113+ return new static ($ URI , $ elements );
110114 }
111115
112116
@@ -118,8 +122,8 @@ public function toXML(DOMElement $parent = null): DOMElement
118122 $ e = $ this ->instantiateParentElement ($ parent );
119123 $ e ->setAttribute ('URI ' , $ this ->uri );
120124
121- foreach ($ this ->references as $ reference ) {
122- $ e -> appendChild ($ e-> ownerDocument -> importNode ( $ reference -> getXML (), true ) );
125+ foreach ($ this ->elements as $ element ) {
126+ $ element -> toXML ($ e );
123127 }
124128
125129 return $ e ;
0 commit comments