@@ -65,11 +65,11 @@ trait HTTPOptionsTrait{
65
65
*/
66
66
protected function HTTPOptionsTrait ():void {
67
67
68
- if (!is_array ($ this ->curl_options )){
68
+ if (!\ is_array ($ this ->curl_options )){
69
69
$ this ->curl_options = [];
70
70
}
71
71
72
- if (!is_string ($ this ->user_agent ) || empty (trim ($ this ->user_agent ))){
72
+ if (!\ is_string ($ this ->user_agent ) || empty (\ trim ($ this ->user_agent ))){
73
73
throw new ClientException ('invalid user agent ' );
74
74
}
75
75
@@ -83,69 +83,69 @@ protected function HTTPOptionsTrait():void{
83
83
protected function setCA ():void {
84
84
85
85
// disable verification if wanted so
86
- if ($ this ->ssl_verifypeer !== true || (isset ($ this ->curl_options [CURLOPT_SSL_VERIFYPEER ]) && !$ this ->curl_options [CURLOPT_SSL_VERIFYPEER ])){
87
- unset($ this ->curl_options [CURLOPT_CAINFO ], $ this ->curl_options [CURLOPT_CAPATH ]);
86
+ if ($ this ->ssl_verifypeer !== true || (isset ($ this ->curl_options [\ CURLOPT_SSL_VERIFYPEER ]) && !$ this ->curl_options [\ CURLOPT_SSL_VERIFYPEER ])){
87
+ unset($ this ->curl_options [\ CURLOPT_CAINFO ], $ this ->curl_options [\ CURLOPT_CAPATH ]);
88
88
89
- $ this ->curl_options [CURLOPT_SSL_VERIFYHOST ] = 0 ;
90
- $ this ->curl_options [CURLOPT_SSL_VERIFYPEER ] = false ;
89
+ $ this ->curl_options [\ CURLOPT_SSL_VERIFYHOST ] = 0 ;
90
+ $ this ->curl_options [\ CURLOPT_SSL_VERIFYPEER ] = false ;
91
91
92
92
return ;
93
93
}
94
94
95
- $ this ->curl_options [CURLOPT_SSL_VERIFYHOST ] = 2 ;
96
- $ this ->curl_options [CURLOPT_SSL_VERIFYPEER ] = true ;
95
+ $ this ->curl_options [\ CURLOPT_SSL_VERIFYHOST ] = 2 ;
96
+ $ this ->curl_options [\ CURLOPT_SSL_VERIFYPEER ] = true ;
97
97
98
98
// a path/dir/link to a CA bundle is given, let's check that
99
- if (is_string ($ this ->ca_info )){
99
+ if (\ is_string ($ this ->ca_info )){
100
100
101
101
// if you - for whatever obscure reason - need to check Windows .lnk links,
102
102
// see http://php.net/manual/en/function.is-link.php#91249
103
103
switch (true ){
104
- case is_dir ($ this ->ca_info ):
105
- case is_link ($ this ->ca_info ) && is_dir (readlink ($ this ->ca_info )): // @codeCoverageIgnore
106
- $ this ->curl_options [CURLOPT_CAPATH ] = $ this ->ca_info ;
107
- unset($ this ->curl_options [CURLOPT_CAINFO ]);
104
+ case \ is_dir ($ this ->ca_info ):
105
+ case \ is_link ($ this ->ca_info ) && \ is_dir (\ readlink ($ this ->ca_info )): // @codeCoverageIgnore
106
+ $ this ->curl_options [\ CURLOPT_CAPATH ] = $ this ->ca_info ;
107
+ unset($ this ->curl_options [\ CURLOPT_CAINFO ]);
108
108
return ;
109
109
110
- case is_file ($ this ->ca_info ):
111
- case is_link ($ this ->ca_info ) && is_file (readlink ($ this ->ca_info )): // @codeCoverageIgnore
112
- $ this ->curl_options [CURLOPT_CAINFO ] = $ this ->ca_info ;
113
- unset($ this ->curl_options [CURLOPT_CAPATH ]);
110
+ case \ is_file ($ this ->ca_info ):
111
+ case \ is_link ($ this ->ca_info ) && \ is_file (\ readlink ($ this ->ca_info )): // @codeCoverageIgnore
112
+ $ this ->curl_options [\ CURLOPT_CAINFO ] = $ this ->ca_info ;
113
+ unset($ this ->curl_options [\ CURLOPT_CAPATH ]);
114
114
return ;
115
115
}
116
116
117
117
throw new ClientException ('invalid path to SSL CA bundle (HTTPOptions::$ca_info): ' .$ this ->ca_info );
118
118
}
119
119
120
120
// we somehow landed here, so let's check if there's a CA bundle given via the cURL options
121
- $ ca = $ this ->curl_options [CURLOPT_CAPATH ] ?? $ this ->curl_options [CURLOPT_CAINFO ] ?? false ;
121
+ $ ca = $ this ->curl_options [\ CURLOPT_CAPATH ] ?? $ this ->curl_options [\ CURLOPT_CAINFO ] ?? false ;
122
122
123
123
if ($ ca ){
124
124
125
125
// just check if the file/path exists
126
126
switch (true ){
127
- case is_dir ($ ca ):
128
- case is_link ($ ca ) && is_dir (readlink ($ ca )): // @codeCoverageIgnore
129
- unset($ this ->curl_options [CURLOPT_CAINFO ]);
127
+ case \ is_dir ($ ca ):
128
+ case \ is_link ($ ca ) && \ is_dir (\ readlink ($ ca )): // @codeCoverageIgnore
129
+ unset($ this ->curl_options [\ CURLOPT_CAINFO ]);
130
130
return ;
131
131
132
- case is_file ($ ca ):
133
- case is_link ($ ca ) && is_file (readlink ($ ca )): // @codeCoverageIgnore
132
+ case \ is_file ($ ca ):
133
+ case \ is_link ($ ca ) && \ is_file (\ readlink ($ ca )): // @codeCoverageIgnore
134
134
return ;
135
135
}
136
136
137
137
throw new ClientException ('invalid path to SSL CA bundle (CURLOPT_CAPATH/CURLOPT_CAINFO): ' .$ ca );
138
138
}
139
139
140
140
// check php.ini options - PHP should find the file by itself
141
- if (file_exists (ini_get ('curl.cainfo ' ))){
141
+ if (\ file_exists (\ ini_get ('curl.cainfo ' ))){
142
142
return ; // @codeCoverageIgnore
143
143
}
144
144
145
145
// this is getting weird. as a last resort, we're going to check some default paths for a CA bundle file
146
146
$ cafiles = [
147
147
// check other php.ini settings
148
- ini_get ('openssl.cafile ' ),
148
+ \ ini_get ('openssl.cafile ' ),
149
149
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
150
150
'/etc/pki/tls/certs/ca-bundle.crt ' ,
151
151
// Ubuntu, Debian (provided by the ca-certificates package)
@@ -169,8 +169,8 @@ protected function setCA():void{
169
169
];
170
170
171
171
foreach ($ cafiles as $ file ){
172
- if (is_file ($ file ) || (is_link ($ file ) && is_file (readlink ($ file )))){
173
- $ this ->curl_options [CURLOPT_CAINFO ] = $ file ;
172
+ if (\ is_file ($ file ) || (\ is_link ($ file ) && \ is_file (\ readlink ($ file )))){
173
+ $ this ->curl_options [\ CURLOPT_CAINFO ] = $ file ;
174
174
return ;
175
175
}
176
176
}
0 commit comments