ILIAS  release_7 Revision v7.30-3-g800a261c036
ilWhiteListUrlValidator Class Reference

Class ilWhiteListUrlValidator. More...

+ Collaboration diagram for ilWhiteListUrlValidator:

Public Member Functions

 __construct (string $url, array $whitelist)
 ilWhiteListUrlValidator constructor. More...
 
 isValid ()
 

Protected Attributes

 $url = ''
 
 $whitelist = []
 

Private Member Functions

 isValidDomain (string $domain)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilWhiteListUrlValidator::__construct ( string  $url,
array  $whitelist 
)

ilWhiteListUrlValidator constructor.

Parameters
string$url
string[]$whitelist

Definition at line 21 of file class.ilWhiteListUrlValidator.php.

22 {
23 $this->url = $url;
24 $this->whitelist = array_filter(array_map(function (string $domain) {
25 return trim($domain); // Used for trimming and type validation (strict primitive type hint)
26 }, $whitelist));
27 }

References $url, and $whitelist.

Member Function Documentation

◆ isValid()

ilWhiteListUrlValidator::isValid ( )
Returns
bool

Definition at line 58 of file class.ilWhiteListUrlValidator.php.

58 : bool
59 {
60 $redirectDomain = parse_url($this->url, PHP_URL_HOST);
61 if (null === $redirectDomain) {
62 return false;
63 }
64
65 return $this->isValidDomain($redirectDomain);
66 }

References isValidDomain().

+ Here is the call graph for this function:

◆ isValidDomain()

ilWhiteListUrlValidator::isValidDomain ( string  $domain)
private
Parameters
string$domain
Returns
bool

Definition at line 33 of file class.ilWhiteListUrlValidator.php.

33 : bool
34 {
35 foreach ($this->whitelist as $validDomain) {
36 if ($domain === $validDomain) {
37 return true;
38 }
39
40 $firstChar = $validDomain[0];
41 if ('.' !== $firstChar) {
42 $validDomain = '.' . $validDomain;
43 }
44
45 if (strlen($domain) > strlen($validDomain)) {
46 if (substr($domain, (0 - strlen($validDomain))) === $validDomain) {
47 return true;
48 }
49 }
50 }
51
52 return false;
53 }

Referenced by isValid().

+ Here is the caller graph for this function:

Field Documentation

◆ $url

ilWhiteListUrlValidator::$url = ''
protected

Definition at line 11 of file class.ilWhiteListUrlValidator.php.

Referenced by __construct().

◆ $whitelist

ilWhiteListUrlValidator::$whitelist = []
protected

Definition at line 14 of file class.ilWhiteListUrlValidator.php.

Referenced by __construct().


The documentation for this class was generated from the following file: