@@ -212,28 +212,27 @@ public static function treeCopyReplace(DomNode $targetNode, DomNode $sourceNode,
212212 /**
213213 * Returns a x509 cert (adding header & footer if required).
214214 *
215- * @param string $cert A x509 unformated cert
216- * @param bool $heads True if we want to include head and footer
215+ * @param string $x509cert A x509 unformated cert
216+ * @param bool $heads True if we want to include head and footer
217217 *
218218 * @return string $x509 Formatted cert
219219 */
220- public static function formatCert ($ cert , $ heads = true )
220+ public static function formatCert ($ x509cert , $ heads = true )
221221 {
222- if (is_null ($ cert )) {
222+ if (is_null ($ x509cert )) {
223223 return ;
224224 }
225225
226- $ x509cert = str_replace (array ("\x0D" , "\r" , "\n" ), "" , $ cert );
227- if (!empty ($ x509cert )) {
228- $ x509cert = str_replace ('-----BEGIN CERTIFICATE----- ' , "" , $ x509cert );
229- $ x509cert = str_replace ('-----END CERTIFICATE----- ' , "" , $ x509cert );
230- $ x509cert = str_replace (' ' , '' , $ x509cert );
226+ if (strpos ($ x509cert , '-----BEGIN CERTIFICATE----- ' ) !== false ) {
227+ $ x509cert = static ::getStringBetween ($ x509cert , '-----BEGIN CERTIFICATE----- ' , '-----END CERTIFICATE----- ' );
228+ }
231229
232- if ($ heads ) {
233- $ x509cert = "-----BEGIN CERTIFICATE----- \n" .chunk_split ($ x509cert , 64 , "\n" )."-----END CERTIFICATE----- \n" ;
234- }
230+ $ x509cert = str_replace (["\x0d" , "\r" , "\n" , " " ], '' , $ x509cert );
235231
232+ if ($ heads && $ x509cert !== '' ) {
233+ $ x509cert = "-----BEGIN CERTIFICATE----- \n" .chunk_split ($ x509cert , 64 , "\n" )."-----END CERTIFICATE----- \n" ;
236234 }
235+
237236 return $ x509cert ;
238237 }
239238
0 commit comments