1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RattfieldNz\SafeUrls\Libraries\Config; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Config. |
7
|
|
|
* |
8
|
|
|
* @category PHP |
9
|
|
|
* |
10
|
|
|
* @author Rob Attfield <[email protected]> |
11
|
|
|
* @license https://github.com/rattfieldnz/safe-urls/blob/master/license.md MIT |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/rattfieldnz/safe-urls/ |
14
|
|
|
*/ |
15
|
|
|
class Config |
16
|
|
|
{ |
17
|
|
|
// Default timeout for API call. |
18
|
|
|
public const DEFAULT_TIMEOUT = 10; |
19
|
|
|
|
20
|
|
|
// Default threat types. |
21
|
|
|
public const DEFAULT_THREAT_TYPES = ['THREAT_TYPE_UNSPECIFIED']; |
22
|
|
|
|
23
|
|
|
// Default threst entry types. |
24
|
|
|
public const DEFAULT_THREAT_ENTRY_TYPES = ['THREAT_ENTRY_TYPE_UNSPECIFIED']; |
25
|
|
|
|
26
|
|
|
// Default threat platform types. |
27
|
|
|
public const DEFAULT_THREAT_PLATFORM_TYPES = ['PLATFORM_TYPE_UNSPECIFIED']; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Retrieve the Google API key. |
31
|
|
|
* |
32
|
|
|
* @return mixed|string|null The Google API key. |
33
|
|
|
*/ |
34
|
9 |
|
public static function googleApiKey() |
35
|
|
|
{ |
36
|
9 |
|
$key = config('safe-urls.google.api_key'); |
37
|
|
|
|
38
|
9 |
|
return !empty($key) ? $key : env('GOOGLE_API_KEY'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Retrieve Google API client id. |
43
|
|
|
* |
44
|
|
|
* @return string The Google API client id. |
45
|
|
|
*/ |
46
|
12 |
|
public static function clientId(): string |
47
|
|
|
{ |
48
|
12 |
|
$clientId = config('safe-urls.google.clientId'); |
49
|
|
|
|
50
|
12 |
|
return !empty($clientId) ? $clientId : ''; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Retrieve the Google API client version. |
55
|
|
|
* |
56
|
|
|
* @return string The Google API client version. |
57
|
|
|
*/ |
58
|
12 |
|
public static function clientVersion(): string |
59
|
|
|
{ |
60
|
12 |
|
$clientVersion = config('safe-urls.google.clientVersion'); |
61
|
|
|
|
62
|
12 |
|
return !empty($clientVersion) ? $clientVersion : ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Retrieve Google Safe Browsing API threat types. |
67
|
|
|
* |
68
|
|
|
* @return array Threat types. |
69
|
|
|
*/ |
70
|
11 |
|
public static function threatTypes(): array |
71
|
|
|
{ |
72
|
11 |
|
$threatTypes = config('safe-urls.google.threat_types'); |
73
|
|
|
|
74
|
11 |
|
return !empty($threatTypes) ? $threatTypes : self::DEFAULT_THREAT_TYPES; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Retrieve Google Safe Browsing API platform types. |
79
|
|
|
* |
80
|
|
|
* @return array Platforms where threats can occur. |
81
|
|
|
*/ |
82
|
11 |
|
public static function platformTypes(): array |
83
|
|
|
{ |
84
|
11 |
|
$platformTypes = config('safe-urls.google.threat_platform_types'); |
85
|
|
|
|
86
|
11 |
|
return !empty($platformTypes) ? $platformTypes : self::DEFAULT_THREAT_PLATFORM_TYPES; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Retrieve Google Safe Browsing API threat entry types. |
91
|
|
|
* |
92
|
|
|
* @return array Threat entry types. |
93
|
|
|
*/ |
94
|
11 |
|
public static function threatEntryTypes(): array |
95
|
|
|
{ |
96
|
11 |
|
$threatEntryTypes = config('safe-urls.google.threat_entry_types'); |
97
|
|
|
|
98
|
11 |
|
return !empty($threatEntryTypes) ? $threatEntryTypes : self::DEFAULT_THREAT_ENTRY_TYPES; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Retrieve set CURL timeout from config, in seconds. |
103
|
|
|
* |
104
|
|
|
* @return int CURL timeout. Default is 10. |
105
|
|
|
*/ |
106
|
1 |
|
public static function curlTimeout(): int |
107
|
|
|
{ |
108
|
1 |
|
$timeout = config('safe-urls.google.timeout'); |
109
|
|
|
|
110
|
1 |
|
return !empty($timeout) ? intval($timeout) : self::DEFAULT_TIMEOUT; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|