dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Convert Special:NewFiles to use OOUI."
[lhc/web/wiklou.git]
/
includes
/
libs
/
MultiHttpClient.php
diff --git
a/includes/libs/MultiHttpClient.php
b/includes/libs/MultiHttpClient.php
index
6ad7741
..
331f2d5
100644
(file)
--- a/
includes/libs/MultiHttpClient.php
+++ b/
includes/libs/MultiHttpClient.php
@@
-75,9
+75,9
@@
class MultiHttpClient {
throw new Exception( "Cannot find CA bundle: " . $this->caBundlePath );
}
}
throw new Exception( "Cannot find CA bundle: " . $this->caBundlePath );
}
}
- static $opts =
array(
+ static $opts =
[
'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost', 'proxy', 'userAgent'
'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost', 'proxy', 'userAgent'
-
)
;
+
]
;
foreach ( $opts as $key ) {
if ( isset( $options[$key] ) ) {
$this->$key = $options[$key];
foreach ( $opts as $key ) {
if ( isset( $options[$key] ) ) {
$this->$key = $options[$key];
@@
-104,9
+104,8
@@
class MultiHttpClient {
* - reqTimeout : post-connection timeout per request (seconds)
* @return array Response array for request
*/
* - reqTimeout : post-connection timeout per request (seconds)
* @return array Response array for request
*/
- final public function run( array $req, array $opts = array() ) {
- $req = $this->runMulti( array( $req ), $opts );
- return $req[0]['response'];
+ final public function run( array $req, array $opts = [] ) {
+ return $this->runMulti( [ $req ], $opts )[0]['response'];
}
/**
}
/**
@@
-135,19
+134,19
@@
class MultiHttpClient {
* @return array $reqs With response array populated for each
* @throws Exception
*/
* @return array $reqs With response array populated for each
* @throws Exception
*/
- public function runMulti( array $reqs, array $opts =
array()
) {
+ public function runMulti( array $reqs, array $opts =
[]
) {
$chm = $this->getCurlMulti();
// Normalize $reqs and add all of the required cURL handles...
$chm = $this->getCurlMulti();
// Normalize $reqs and add all of the required cURL handles...
- $handles =
array()
;
+ $handles =
[]
;
foreach ( $reqs as $index => &$req ) {
foreach ( $reqs as $index => &$req ) {
- $req['response'] =
array(
+ $req['response'] =
[
'code' => 0,
'reason' => '',
'code' => 0,
'reason' => '',
- 'headers' =>
array()
,
+ 'headers' =>
[]
,
'body' => '',
'error' => ''
'body' => '',
'error' => ''
-
)
;
+
]
;
if ( isset( $req[0] ) ) {
$req['method'] = $req[0]; // short-form
unset( $req[0] );
if ( isset( $req[0] ) ) {
$req['method'] = $req[0]; // short-form
unset( $req[0] );
@@
-161,8
+160,8
@@
class MultiHttpClient {
} elseif ( !isset( $req['url'] ) ) {
throw new Exception( "Request has no 'url' field set." );
}
} elseif ( !isset( $req['url'] ) ) {
throw new Exception( "Request has no 'url' field set." );
}
- $req['query'] = isset( $req['query'] ) ? $req['query'] :
array()
;
- $headers =
array()
; // normalized headers
+ $req['query'] = isset( $req['query'] ) ? $req['query'] :
[]
;
+ $headers =
[]
; // normalized headers
if ( isset( $req['headers'] ) ) {
foreach ( $req['headers'] as $name => $value ) {
$headers[strtolower( $name )] = $value;
if ( isset( $req['headers'] ) ) {
foreach ( $req['headers'] as $name => $value ) {
$headers[strtolower( $name )] = $value;
@@
-194,7
+193,7
@@
class MultiHttpClient {
// @TODO: use a per-host rolling handle window (e.g. CURLMOPT_MAX_HOST_CONNECTIONS)
$batches = array_chunk( $indexes, $this->maxConnsPerHost );
// @TODO: use a per-host rolling handle window (e.g. CURLMOPT_MAX_HOST_CONNECTIONS)
$batches = array_chunk( $indexes, $this->maxConnsPerHost );
- $infos =
array()
;
+ $infos =
[]
;
foreach ( $batches as $batch ) {
// Attach all cURL handles for this batch
foreach ( $batches as $batch ) {
// Attach all cURL handles for this batch
@@
-272,7
+271,7
@@
class MultiHttpClient {
* @return resource
* @throws Exception
*/
* @return resource
* @throws Exception
*/
- protected function getCurlHandle( array &$req, array $opts =
array()
) {
+ protected function getCurlHandle( array &$req, array $opts =
[]
) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT,
$ch = curl_init();
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT,
@@
-292,8
+291,8
@@
class MultiHttpClient {
$url = $req['url'];
// PHP_QUERY_RFC3986 is PHP 5.4+ only
$query = str_replace(
$url = $req['url'];
// PHP_QUERY_RFC3986 is PHP 5.4+ only
$query = str_replace(
-
array( '+', '%7E' )
,
-
array( '%20', '~' )
,
+
[ '+', '%7E' ]
,
+
[ '%20', '~' ]
,
http_build_query( $req['query'], '', '&' )
);
if ( $query != '' ) {
http_build_query( $req['query'], '', '&' )
);
if ( $query != '' ) {
@@
-363,7
+362,7
@@
class MultiHttpClient {
$req['headers']['user-agent'] = $this->userAgent;
}
$req['headers']['user-agent'] = $this->userAgent;
}
- $headers =
array()
;
+ $headers =
[]
;
foreach ( $req['headers'] as $name => $value ) {
if ( strpos( $name, ': ' ) ) {
throw new Exception( "Headers cannot have ':' in the name." );
foreach ( $req['headers'] as $name => $value ) {
if ( strpos( $name, ': ' ) ) {
throw new Exception( "Headers cannot have ':' in the name." );
@@
-375,7
+374,7
@@
class MultiHttpClient {
curl_setopt( $ch, CURLOPT_HEADERFUNCTION,
function ( $ch, $header ) use ( &$req ) {
$length = strlen( $header );
curl_setopt( $ch, CURLOPT_HEADERFUNCTION,
function ( $ch, $header ) use ( &$req ) {
$length = strlen( $header );
- $matches =
array()
;
+ $matches =
[]
;
if ( preg_match( "/^(HTTP\/1\.[01]) (\d{3}) (.*)/", $header, $matches ) ) {
$req['response']['code'] = (int)$matches[2];
$req['response']['reason'] = trim( $matches[3] );
if ( preg_match( "/^(HTTP\/1\.[01]) (\d{3}) (.*)/", $header, $matches ) ) {
$req['response']['code'] = (int)$matches[2];
$req['response']['reason'] = trim( $matches[3] );