1 | <?php |
||||
2 | |||||
3 | namespace Mediumart\Orange\SMS\Http; |
||||
4 | |||||
5 | use GuzzleHttp\Client; |
||||
6 | |||||
7 | abstract class SMSClientRequest |
||||
8 | { |
||||
9 | /** |
||||
10 | * base api uri. |
||||
11 | */ |
||||
12 | const BASE_URI = 'https://api.orange.com'; |
||||
13 | |||||
14 | /** |
||||
15 | * Describes the SSL certificate verification behavior of a request. |
||||
16 | */ |
||||
17 | protected static $verify_ssl = true; |
||||
18 | |||||
19 | /** |
||||
20 | * @var Client |
||||
21 | */ |
||||
22 | protected static $httpClient; |
||||
23 | |||||
24 | /** |
||||
25 | * Http request method. |
||||
26 | * |
||||
27 | * @return string |
||||
28 | */ |
||||
29 | abstract public function method(); |
||||
30 | |||||
31 | /** |
||||
32 | * The uri for the current request. |
||||
33 | * |
||||
34 | * @return string |
||||
35 | */ |
||||
36 | abstract public function uri(); |
||||
37 | |||||
38 | /** |
||||
39 | * Http request options. |
||||
40 | * |
||||
41 | * @return array |
||||
42 | */ |
||||
43 | 3 | public function options() |
|||
44 | { |
||||
45 | 3 | return []; |
|||
46 | } |
||||
47 | |||||
48 | /** |
||||
49 | * Set the SSL certificate verification behavior of a request. |
||||
50 | * |
||||
51 | * @param bool|string $value |
||||
52 | * @return $this |
||||
53 | */ |
||||
54 | 17 | public static function verify($value) |
|||
55 | { |
||||
56 | 17 | if (is_bool($value) || is_string($value)) { |
|||
0 ignored issues
–
show
introduced
by
![]() |
|||||
57 | 17 | static::$verify_ssl = $value; |
|||
58 | } |
||||
59 | 17 | } |
|||
60 | |||||
61 | /** |
||||
62 | * Set the http client. |
||||
63 | * |
||||
64 | * @param Client $client |
||||
65 | */ |
||||
66 | 10 | public static function setHttpClient(Client $client) |
|||
67 | { |
||||
68 | 10 | static::$httpClient = $client; |
|||
69 | 10 | } |
|||
70 | |||||
71 | /** |
||||
72 | * Get the http client. |
||||
73 | * |
||||
74 | * @return \GuzzleHttp\Client |
||||
75 | */ |
||||
76 | 11 | public static function getHttpClient() |
|||
77 | { |
||||
78 | 11 | if (static::$httpClient && |
|||
79 | 11 | static::$httpClient->getConfig('verify') === static::$verify_ssl |
|||
0 ignored issues
–
show
The function
GuzzleHttp\Client::getConfig() has been deprecated: Client::getConfig will be removed in guzzlehttp/guzzle:8.0.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
80 | ) { |
||||
81 | 10 | return static::$httpClient; |
|||
82 | } |
||||
83 | |||||
84 | 1 | return new Client(['http_errors' => false, 'verify' => static::$verify_ssl]); |
|||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * Execute the request. |
||||
89 | * |
||||
90 | * @param array|null $options |
||||
91 | * @return mixed|\Psr\Http\Message\ResponseInterface |
||||
92 | */ |
||||
93 | 9 | final public function execute($options = null) |
|||
94 | { |
||||
95 | return $this |
||||
96 | 9 | ->getHttpClient() |
|||
97 | 9 | ->request( |
|||
98 | 9 | $this->method(), |
|||
99 | 9 | $this->uri(), |
|||
100 | 9 | $options ?: $this->options() |
|||
101 | ); |
||||
102 | } |
||||
103 | |||||
104 | /** |
||||
105 | * Normalize phone number. |
||||
106 | * |
||||
107 | * @param $phone |
||||
108 | * @return string |
||||
109 | */ |
||||
110 | 3 | protected function normalizePhoneNumber($phone) |
|||
111 | { |
||||
112 | 3 | $phone = (string) $phone; |
|||
113 | |||||
114 | 3 | if (substr($phone, 0, 1) !== '+') { |
|||
115 | 1 | return '+' . $phone; |
|||
116 | } |
||||
117 | |||||
118 | 3 | return $phone; |
|||
119 | } |
||||
120 | } |
||||
121 |