|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ddlzz\AmoAPI\Validator; |
|
4
|
|
|
|
|
5
|
|
|
use ddlzz\AmoAPI\Exception\InvalidArgumentException; |
|
6
|
|
|
use ddlzz\AmoAPI\Utils\StringUtil; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class SettingsValidator. |
|
10
|
|
|
* |
|
11
|
|
|
* @author ddlzz |
|
12
|
|
|
*/ |
|
13
|
|
|
class SettingsValidator |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param string $scheme |
|
17
|
|
|
* |
|
18
|
|
|
* @throws InvalidArgumentException |
|
19
|
|
|
* |
|
20
|
|
|
* @return bool |
|
21
|
|
|
*/ |
|
22
|
4 |
|
public function validateScheme($scheme) |
|
23
|
|
|
{ |
|
24
|
4 |
|
if (!StringUtil::isOnlyLetters($scheme)) { |
|
25
|
3 |
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid scheme', $scheme)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
return true; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $domain |
|
33
|
|
|
* |
|
34
|
|
|
* @throws InvalidArgumentException |
|
35
|
|
|
* |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
4 |
|
public function validateDomain($domain) |
|
39
|
|
|
{ |
|
40
|
4 |
|
if (!StringUtil::isDomain($domain)) { |
|
41
|
3 |
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid domain', $domain)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $userAgent |
|
49
|
|
|
* |
|
50
|
|
|
* @throws InvalidArgumentException |
|
51
|
|
|
* |
|
52
|
|
|
* @return bool |
|
53
|
|
|
*/ |
|
54
|
4 |
|
public function validateUserAgent($userAgent) |
|
55
|
|
|
{ |
|
56
|
4 |
|
if (!StringUtil::isText($userAgent)) { |
|
57
|
3 |
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid user agent', $userAgent)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
return true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $paths |
|
65
|
|
|
* |
|
66
|
|
|
* @throws InvalidArgumentException |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
4 |
|
public function validateMethodsPaths(array $paths) |
|
71
|
|
|
{ |
|
72
|
4 |
|
if (empty($paths)) { |
|
73
|
1 |
|
throw new InvalidArgumentException('An array "method Paths" must not be empty'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
foreach ($paths as $key => $item) { |
|
77
|
3 |
|
if (empty($item)) { |
|
78
|
1 |
|
throw new InvalidArgumentException(sprintf('An array item "%s" must not be empty', $key)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
if (!StringUtil::isUrlPath($item)) { |
|
82
|
2 |
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid method path', $item)); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $path |
|
91
|
|
|
* |
|
92
|
|
|
* @throws InvalidArgumentException |
|
93
|
|
|
* |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
4 |
|
public function validateCookiePath($path) |
|
97
|
|
|
{ |
|
98
|
4 |
|
if (!StringUtil::isFilePath($path)) { |
|
99
|
3 |
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid file path', $path)); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|