Skip to content

Commit 40e2fbe

Browse files
author
Nik Karbaum
committed
Ability to pass protocol regex
1 parent 3d6ccf1 commit 40e2fbe

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/Saml2/Utils.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class Utils
5151
*/
5252
private static $_protocol;
5353

54+
/**
55+
* @var string
56+
*/
57+
private static $_protocolRegex = '@^https?://@i';
58+
5459
/**
5560
* @var int|null
5661
*/
@@ -285,8 +290,11 @@ public static function redirect($url, array $parameters = array(), $stay = false
285290
$url = self::getSelfURLhost() . $url;
286291
}
287292

288-
/* Verify that the URL is to a http or https site. */
289-
$wrongProtocol = !preg_match('@^https?://@i', $url);
293+
/**
294+
* Verify that the URL matches the regex for the protocol.
295+
* By default this will check for http and https
296+
*/
297+
$wrongProtocol = !preg_match(self::$_protocolRegex, $url);
290298
$url = filter_var($url, FILTER_VALIDATE_URL);
291299
if ($wrongProtocol || empty($url)) {
292300
throw new Error(
@@ -333,6 +341,16 @@ public static function redirect($url, array $parameters = array(), $stay = false
333341
exit();
334342
}
335343

344+
/**
345+
* @var $protocolRegex string
346+
*/
347+
public static function setProtocolRegex($protocolRegex)
348+
{
349+
if (!empty($protocolRegex)) {
350+
self::$_protocolRegex = $protocolRegex;
351+
}
352+
}
353+
336354
/**
337355
* Set the Base URL value.
338356
*

0 commit comments

Comments
 (0)