1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LiquidWeb\SslCertificate; |
4
|
|
|
|
5
|
|
|
function verifyWebUrl(string $protocol) : bool |
6
|
|
|
{ |
7
|
|
|
return in_array($protocol, [null, 'http', 'https']); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
function isValidFqdn($domain): bool |
11
|
|
|
{ |
12
|
|
|
if (filter_var($domain, FILTER_VALIDATE_DOMAIN) === false) { |
13
|
|
|
return false; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
return true; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function isValidUrl($domain): bool |
20
|
|
|
{ |
21
|
|
|
if (filter_var($domain, FILTER_VALIDATE_URL) === false) { |
22
|
|
|
return false; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return true; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
function starts_with($haystack, $needles): bool |
29
|
|
|
{ |
30
|
8 |
|
foreach ((array) $needles as $needle) { |
31
|
8 |
|
if ($needle != '' && substr($haystack, 0, length($needle)) === (string) $needle) { |
32
|
8 |
|
return true; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
7 |
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Determine if a given string ends with a given substring. |
41
|
|
|
* |
42
|
|
|
* @param string $haystack |
43
|
|
|
* @param string|array $needles |
44
|
|
|
* |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
function ends_with(string $haystack, $needles): bool |
48
|
|
|
{ |
49
|
3 |
|
foreach ((array) $needles as $needle) { |
50
|
3 |
|
if ((string) $needle === substr($haystack, -length($needle))) { |
51
|
3 |
|
return true; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns the portion of string specified by the start and length parameters. |
60
|
|
|
* |
61
|
|
|
* @param string $string |
62
|
|
|
* @param int $start |
63
|
|
|
* @param int|null $length |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
function substr(string $string, int $start, int $length = null): string |
68
|
|
|
{ |
69
|
10 |
|
return mb_substr($string, $start, $length, 'UTF-8'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the length of the given string. |
74
|
|
|
* |
75
|
|
|
* @param string $value |
76
|
|
|
* |
77
|
|
|
* @return int |
78
|
|
|
*/ |
79
|
|
|
function length(string $value): int |
80
|
|
|
{ |
81
|
10 |
|
return mb_strlen($value); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Determine if a given string contains a given substring. |
86
|
|
|
* |
87
|
|
|
* @param string $haystack |
88
|
|
|
* @param string|array $needles |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
function str_contains(string $haystack, $needles): bool |
93
|
|
|
{ |
94
|
10 |
|
foreach ((array) $needles as $needle) { |
95
|
10 |
|
if ($needle != '' && mb_strpos($haystack, $needle) !== false) { |
96
|
10 |
|
return true; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
6 |
|
return false; |
101
|
|
|
} |
102
|
|
|
|