-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathServiceClient.php
More file actions
104 lines (88 loc) · 2.58 KB
/
Copy pathServiceClient.php
File metadata and controls
104 lines (88 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
declare(strict_types=1);
namespace MaxMind\MinFraud;
use MaxMind\Exception\InvalidInputException;
use MaxMind\WebService\Client;
abstract class ServiceClient
{
public const VERSION = 'v3.6.0';
/**
* @var Client
*/
protected $client;
/**
* @var string
*/
protected static $host = 'minfraud.maxmind.com';
/**
* @var string
*/
protected static $basePath = '/minfraud/v2.0/';
/**
* @var bool
*/
protected $validateInput = true;
/**
* @param int $accountId your account ID
* @param string $licenseKey your license key
* @param array<string, mixed> $options options for the client
*/
public function __construct(
int $accountId,
string $licenseKey,
array $options = []
) {
if (!isset($options['host'])) {
$options['host'] = self::$host;
}
$options['userAgent'] = $this->userAgent();
$this->client = new Client($accountId, $licenseKey, $options);
if (isset($options['validateInput'])) {
$this->validateInput = $options['validateInput'];
}
}
/**
* @return string the prefix for the User-Agent header
*/
protected function userAgent(): string
{
return 'minFraud-API/' . self::VERSION;
}
protected function maybeThrowInvalidInputException(string $msg): void
{
if ($this->validateInput) {
throw new InvalidInputException($msg);
}
}
/**
* @ignore
*
* @param array<string, mixed> $array the parent array
* @param string $key the key to remove
* @param list<string> $types the expected types
*/
protected function remove(array &$array, string $key, array $types = ['string']): mixed
{
if (\array_key_exists($key, $array)) {
$value = $array[$key];
$actualType = \gettype($value);
if ($value !== null && !\in_array($actualType, $types, true)) {
$this->maybeThrowInvalidInputException(
"Expected $key to be in [" . implode(', ', $types) . "] but was $actualType",
);
}
unset($array[$key]);
return $value;
}
return null;
}
/**
* @param array<mixed> $values
*/
protected function verifyEmpty(array $values): void
{
if (\count($values) !== 0) {
$this->maybeThrowInvalidInputException('Unknown keys in array: ' . implode(', ', array_keys($values)));
}
}
}