ILIAS  release_8 Revision v8.24
ilWhiteListUrlValidator Class Reference

Class ilWhiteListUrlValidator. More...

+ Collaboration diagram for ilWhiteListUrlValidator:

Public Member Functions

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

Protected Attributes

string $url = ''
 
array $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 34 of file class.ilWhiteListUrlValidator.php.

35 {
36 $this->url = $url;
37 $this->whitelist = array_filter(array_map(static function (string $domain) {
38 return trim($domain); // Used for trimming and type validation (strict primitive type hint)
39 }, $whitelist));
40 }

References $url, and $whitelist.

Member Function Documentation

◆ isValid()

ilWhiteListUrlValidator::isValid ( )

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

65 : bool
66 {
67 $redirectDomain = parse_url($this->url, PHP_URL_HOST);
68 if (null === $redirectDomain) {
69 return false;
70 }
71
72 return $this->isValidDomain($redirectDomain);
73 }

References isValidDomain().

+ Here is the call graph for this function:

◆ isValidDomain()

ilWhiteListUrlValidator::isValidDomain ( string  $domain)
private

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

42 : bool
43 {
44 foreach ($this->whitelist as $validDomain) {
45 if ($domain === $validDomain) {
46 return true;
47 }
48
49 $firstChar = $validDomain[0];
50 if ('.' !== $firstChar) {
51 $validDomain = '.' . $validDomain;
52 }
53
54 if ((strlen($domain) > strlen($validDomain)) && substr(
55 $domain,
56 (0 - strlen($validDomain))
57 ) === $validDomain) {
58 return true;
59 }
60 }
61
62 return false;
63 }

Referenced by isValid().

+ Here is the caller graph for this function:

Field Documentation

◆ $url

string ilWhiteListUrlValidator::$url = ''
protected

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

Referenced by __construct().

◆ $whitelist

array ilWhiteListUrlValidator::$whitelist = []
protected

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

Referenced by __construct().


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