3030use DOMException ;
3131use SimpleSAML \Configuration ;
3232use SimpleSAML \Logger ;
33+ use SimpleSAML \XML \DOMDocumentFactory ;
3334
3435class Cas20
3536{
@@ -102,7 +103,8 @@ public function getProxyGrantingTicketIOU(): ?string
102103 */
103104 public function getValidateSuccessResponse (string $ username ): string
104105 {
105- $ xmlDocument = new DOMDocument ("1.0 " );
106+ $ xmlDocument = DOMDocumentFactory::create ();
107+ $ xmlDocument ->formatOutput = true ;
106108
107109 $ root = $ xmlDocument ->createElement ("cas:serviceResponse " );
108110 $ root ->setAttributeNS ('http://www.w3.org/2000/xmlns/ ' , 'xmlns:cas ' , 'http://www.yale.edu/tp/cas ' );
@@ -154,7 +156,7 @@ public function getValidateSuccessResponse(string $username): string
154156 $ root ->appendChild ($ casSuccess );
155157 $ xmlDocument ->appendChild ($ root );
156158
157- return $ this -> workAroundForBuggyJasigXmlParser ( $ xmlDocument ->saveXML () );
159+ return $ xmlDocument ->saveXML ();
158160 }
159161
160162
@@ -165,7 +167,7 @@ public function getValidateSuccessResponse(string $username): string
165167 */
166168 public function getValidateFailureResponse (string $ errorCode , string $ explanation ): string
167169 {
168- $ xmlDocument = new DOMDocument ( " 1.0 " );
170+ $ xmlDocument = DOMDocumentFactory:: create ( );
169171
170172 $ root = $ xmlDocument ->createElement ("cas:serviceResponse " );
171173 $ root ->setAttributeNS ('http://www.w3.org/2000/xmlns/ ' , 'xmlns:cas ' , 'http://www.yale.edu/tp/cas ' );
@@ -182,7 +184,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
182184
183185 $ xmlDocument ->appendChild ($ root );
184186
185- return $ this -> workAroundForBuggyJasigXmlParser ( $ xmlDocument ->saveXML () );
187+ return $ xmlDocument ->saveXML ();
186188 }
187189
188190
@@ -192,7 +194,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
192194 */
193195 public function getProxySuccessResponse (string $ proxyTicketId ): string
194196 {
195- $ xmlDocument = new DOMDocument ( " 1.0 " );
197+ $ xmlDocument = DOMDocumentFactory:: create ( );
196198
197199 $ root = $ xmlDocument ->createElement ("cas:serviceResponse " );
198200 $ root ->setAttributeNS ('http://www.w3.org/2000/xmlns/ ' , 'xmlns:cas ' , 'http://www.yale.edu/tp/cas ' );
@@ -207,7 +209,7 @@ public function getProxySuccessResponse(string $proxyTicketId): string
207209 $ root ->appendChild ($ casProxySuccess );
208210 $ xmlDocument ->appendChild ($ root );
209211
210- return $ this -> workAroundForBuggyJasigXmlParser ( $ xmlDocument ->saveXML () );
212+ return $ xmlDocument ->saveXML ();
211213 }
212214
213215
@@ -218,7 +220,7 @@ public function getProxySuccessResponse(string $proxyTicketId): string
218220 */
219221 public function getProxyFailureResponse (string $ errorCode , string $ explanation ): string
220222 {
221- $ xmlDocument = new DOMDocument ( " 1.0 " );
223+ $ xmlDocument = DOMDocumentFactory:: create ( );
222224
223225 $ root = $ xmlDocument ->createElement ("cas:serviceResponse " );
224226 $ root ->setAttributeNS ('http://www.w3.org/2000/xmlns/ ' , 'xmlns:cas ' , 'http://www.yale.edu/tp/cas ' );
@@ -235,18 +237,7 @@ public function getProxyFailureResponse(string $errorCode, string $explanation):
235237
236238 $ xmlDocument ->appendChild ($ root );
237239
238- return $ this ->workAroundForBuggyJasigXmlParser ($ xmlDocument ->saveXML ());
239- }
240-
241-
242- /**
243- * @param string $xmlString
244- * @return string
245- */
246- private function workAroundForBuggyJasigXmlParser (string $ xmlString ): string
247- {
248- // when will people stop hand coding xml handling....?
249- return str_replace ('>< ' , '> ' . PHP_EOL . '< ' , str_replace (PHP_EOL , '' , $ xmlString ));
240+ return $ xmlDocument ->saveXML ();
250241 }
251242
252243
0 commit comments