@@ -25,12 +25,12 @@ class CurlDownloader
2525
2626 private static $ options = [
2727 'http ' => [
28- 'method ' => CURLOPT_CUSTOMREQUEST ,
29- 'content ' => CURLOPT_POSTFIELDS ,
28+ 'method ' => \ CURLOPT_CUSTOMREQUEST ,
29+ 'content ' => \ CURLOPT_POSTFIELDS ,
3030 ],
3131 'ssl ' => [
32- 'cafile ' => CURLOPT_CAINFO ,
33- 'capath ' => CURLOPT_CAPATH ,
32+ 'cafile ' => \ CURLOPT_CAINFO ,
33+ 'capath ' => \ CURLOPT_CAPATH ,
3434 ],
3535 ];
3636
@@ -46,15 +46,15 @@ class CurlDownloader
4646 public function __construct ()
4747 {
4848 $ this ->multiHandle = $ mh = curl_multi_init ();
49- curl_multi_setopt ($ mh , CURLMOPT_PIPELINING , /*CURLPIPE_MULTIPLEX*/ 2 );
49+ curl_multi_setopt ($ mh , \ CURLMOPT_PIPELINING , /*CURLPIPE_MULTIPLEX*/ 2 );
5050 if (\defined ('CURLMOPT_MAX_HOST_CONNECTIONS ' )) {
51- curl_multi_setopt ($ mh , CURLMOPT_MAX_HOST_CONNECTIONS , 8 );
51+ curl_multi_setopt ($ mh , \ CURLMOPT_MAX_HOST_CONNECTIONS , 8 );
5252 }
5353
5454 $ this ->shareHandle = $ sh = curl_share_init ();
55- curl_share_setopt ($ sh , CURLSHOPT_SHARE , CURL_LOCK_DATA_COOKIE );
56- curl_share_setopt ($ sh , CURLSHOPT_SHARE , CURL_LOCK_DATA_DNS );
57- curl_share_setopt ($ sh , CURLSHOPT_SHARE , CURL_LOCK_DATA_SSL_SESSION );
55+ curl_share_setopt ($ sh , \ CURLSHOPT_SHARE , \ CURL_LOCK_DATA_COOKIE );
56+ curl_share_setopt ($ sh , \ CURLSHOPT_SHARE , \ CURL_LOCK_DATA_DNS );
57+ curl_share_setopt ($ sh , \ CURLSHOPT_SHARE , \ CURL_LOCK_DATA_SSL_SESSION );
5858 }
5959
6060 public function get ($ origin , $ url , $ context , $ file )
@@ -72,21 +72,21 @@ public function get($origin, $url, $context, $file)
7272 $ headers = array_diff ($ params ['options ' ]['http ' ]['header ' ], ['Connection: close ' ]);
7373
7474 if (!isset ($ params ['options ' ]['http ' ]['protocol_version ' ])) {
75- curl_setopt ($ ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
75+ curl_setopt ($ ch , \ CURLOPT_HTTP_VERSION , \ CURL_HTTP_VERSION_1_0 );
7676 } else {
7777 $ headers [] = 'Connection: keep-alive ' ;
78- if (0 === strpos ($ url , 'https:// ' ) && \defined ('CURL_VERSION_HTTP2 ' ) && \defined ('CURL_HTTP_VERSION_2_0 ' ) && (CURL_VERSION_HTTP2 & curl_version ()['features ' ])) {
79- curl_setopt ($ ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_2_0 );
78+ if (0 === strpos ($ url , 'https:// ' ) && \defined ('CURL_VERSION_HTTP2 ' ) && \defined ('CURL_HTTP_VERSION_2_0 ' ) && (\ CURL_VERSION_HTTP2 & curl_version ()['features ' ])) {
79+ curl_setopt ($ ch , \ CURLOPT_HTTP_VERSION , \ CURL_HTTP_VERSION_2_0 );
8080 }
8181 }
8282
83- curl_setopt ($ ch , CURLOPT_URL , $ url );
84- curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
85- curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
86- curl_setopt ($ ch , CURLOPT_DNS_USE_GLOBAL_CACHE , false );
87- curl_setopt ($ ch , CURLOPT_WRITEHEADER , $ hd );
88- curl_setopt ($ ch , CURLOPT_FILE , $ fd );
89- curl_setopt ($ ch , CURLOPT_SHARE , $ this ->shareHandle );
83+ curl_setopt ($ ch , \ CURLOPT_URL , $ url );
84+ curl_setopt ($ ch , \ CURLOPT_HTTPHEADER , $ headers );
85+ curl_setopt ($ ch , \ CURLOPT_FOLLOWLOCATION , true );
86+ curl_setopt ($ ch , \ CURLOPT_DNS_USE_GLOBAL_CACHE , false );
87+ curl_setopt ($ ch , \ CURLOPT_WRITEHEADER , $ hd );
88+ curl_setopt ($ ch , \ CURLOPT_FILE , $ fd );
89+ curl_setopt ($ ch , \ CURLOPT_SHARE , $ this ->shareHandle );
9090
9191 foreach (self ::$ options as $ type => $ options ) {
9292 foreach ($ options as $ name => $ curlopt ) {
@@ -106,7 +106,7 @@ public function get($origin, $url, $context, $file)
106106 ];
107107
108108 curl_multi_add_handle ($ this ->multiHandle , $ ch );
109- $ params ['notification ' ](STREAM_NOTIFY_RESOLVE , STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , 0 , false );
109+ $ params ['notification ' ](\ STREAM_NOTIFY_RESOLVE , \ STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , 0 , false );
110110 $ active = true ;
111111
112112 try {
@@ -128,7 +128,7 @@ public function get($origin, $url, $context, $file)
128128 if ('' !== curl_error ($ h )) {
129129 throw new TransportException (curl_error ($ h ));
130130 }
131- if ($ job ['file ' ] && CURLE_OK === curl_errno ($ h ) && !isset ($ this ->exceptions [$ i ])) {
131+ if ($ job ['file ' ] && \ CURLE_OK === curl_errno ($ h ) && !isset ($ this ->exceptions [$ i ])) {
132132 fclose ($ job ['fd ' ]);
133133 rename ($ job ['file ' ].'~ ' , $ job ['file ' ]);
134134 }
@@ -158,8 +158,8 @@ public function get($origin, $url, $context, $file)
158158 }
159159 }
160160
161- if ('' !== curl_error ($ ch ) || CURLE_OK !== curl_errno ($ ch )) {
162- $ this ->exceptions [(int ) $ ch ] = new TransportException (curl_error ($ ch ), curl_getinfo ($ ch , CURLINFO_HTTP_CODE ) ?: 0 );
161+ if ('' !== curl_error ($ ch ) || \ CURLE_OK !== curl_errno ($ ch )) {
162+ $ this ->exceptions [(int ) $ ch ] = new TransportException (curl_error ($ ch ), curl_getinfo ($ ch , \ CURLINFO_HTTP_CODE ) ?: 0 );
163163 }
164164 if (isset ($ this ->exceptions [(int ) $ ch ])) {
165165 throw $ this ->exceptions [(int ) $ ch ];
@@ -193,24 +193,24 @@ private function onProgress($ch, callable $notify, array $progress, array $previ
193193 }
194194
195195 if (!$ previousProgress ['http_code ' ] && $ progress ['http_code ' ] && $ progress ['http_code ' ] < 200 || 400 <= $ progress ['http_code ' ]) {
196- $ code = 403 === $ progress ['http_code ' ] ? STREAM_NOTIFY_AUTH_RESULT : STREAM_NOTIFY_FAILURE ;
197- $ notify ($ code , STREAM_NOTIFY_SEVERITY_ERR , curl_error ($ ch ), $ progress ['http_code ' ], 0 , 0 , false );
196+ $ code = 403 === $ progress ['http_code ' ] ? \ STREAM_NOTIFY_AUTH_RESULT : \ STREAM_NOTIFY_FAILURE ;
197+ $ notify ($ code , \ STREAM_NOTIFY_SEVERITY_ERR , curl_error ($ ch ), $ progress ['http_code ' ], 0 , 0 , false );
198198 }
199199
200200 if ($ previousProgress ['download_content_length ' ] < $ progress ['download_content_length ' ]) {
201- $ notify (STREAM_NOTIFY_FILE_SIZE_IS , STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , (int ) $ progress ['download_content_length ' ], false );
201+ $ notify (\ STREAM_NOTIFY_FILE_SIZE_IS , \ STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , (int ) $ progress ['download_content_length ' ], false );
202202 }
203203
204204 if ($ previousProgress ['size_download ' ] < $ progress ['size_download ' ]) {
205- $ notify (STREAM_NOTIFY_PROGRESS , STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , (int ) $ progress ['size_download ' ], (int ) $ progress ['download_content_length ' ], false );
205+ $ notify (\ STREAM_NOTIFY_PROGRESS , \ STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , (int ) $ progress ['size_download ' ], (int ) $ progress ['download_content_length ' ], false );
206206 }
207207 }
208208
209209 private function finishProgress ($ ch , callable $ notify , array $ progress )
210210 {
211211 if ($ progress ['download_content_length ' ] < 0 ) {
212- $ notify (STREAM_NOTIFY_FILE_SIZE_IS , STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , (int ) $ progress ['size_download ' ], false );
213- $ notify (STREAM_NOTIFY_PROGRESS , STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , (int ) $ progress ['size_download ' ], (int ) $ progress ['size_download ' ], false );
212+ $ notify (\ STREAM_NOTIFY_FILE_SIZE_IS , \ STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , 0 , (int ) $ progress ['size_download ' ], false );
213+ $ notify (\ STREAM_NOTIFY_PROGRESS , \ STREAM_NOTIFY_SEVERITY_INFO , '' , 0 , (int ) $ progress ['size_download ' ], (int ) $ progress ['size_download ' ], false );
214214 }
215215 }
216216}
0 commit comments