/** @var MultiHttpClient */
protected $http;
/** @var Array Map of (prefix => VirtualRESTService) */
- protected $instances = array();
+ protected $instances = [];
const VALID_MOUNT_REGEX = '#^/[0-9a-z]+/([0-9a-z]+/)*$#';
return ( $al < $bl ) ? 1 : -1; // largest prefix first
};
- $matches = array(); // matching prefixes (mount points)
+ $matches = []; // matching prefixes (mount points)
foreach ( $this->instances as $prefix => $service ) {
if ( strpos( $path, $prefix ) === 0 ) {
$matches[] = $prefix;
// Return the most specific prefix and corresponding service
return isset( $matches[0] )
- ? array( $matches[0], $this->instances[$matches[0]] )
- : array( null, null );
+ ? [ $matches[0], $this->instances[$matches[0]] ]
+ : [ null, null ];
}
/**
* @return array Response array for request
*/
public function run( array $req ) {
- $responses = $this->runMulti( array( $req ) );
- return $responses[0];
+ return $this->runMulti( [ $req ] )[0];
}
/**
$req['url'] = $req[1]; // short-form
unset( $req[1] );
}
- $req['chain'] = array(); // chain or list of replaced requests
+ $req['chain'] = []; // chain or list of replaced requests
}
unset( $req ); // don't assign over this by accident
$curUniqueId = 0;
- $armoredIndexMap = array(); // (original index => new index)
+ $armoredIndexMap = []; // (original index => new index)
- $doneReqs = array(); // (index => request)
- $executeReqs = array(); // (index => request)
- $replaceReqsByService = array(); // (prefix => index => request)
- $origPending = array(); // (index => 1) for original requests
+ $doneReqs = []; // (index => request)
+ $executeReqs = []; // (index => request)
+ $replaceReqsByService = []; // (prefix => index => request)
+ $origPending = []; // (index => 1) for original requests
foreach ( $reqs as $origIndex => $req ) {
// Re-index keys to consecutive integers (they will be swapped back later)
}
// Track requests executed this round that have a prefix/service.
// Note that this also includes requests where 'response' was forced.
- $checkReqIndexesByPrefix = array();
+ $checkReqIndexesByPrefix = [];
// Resolve the virtual URLs valid and qualified HTTP(S) URLs
// and add any required authentication headers for the backend.
// Services can also replace requests with new ones, either to
// defer the original or to set a proxy response to the original.
- $newReplaceReqsByService = array();
+ $newReplaceReqsByService = [];
foreach ( $replaceReqsByService as $prefix => $servReqs ) {
$service = $this->instances[$prefix];
foreach ( $service->onRequests( $servReqs, $idFunc ) as $index => $req ) {
$doneReqs[$index] = $ranReq;
unset( $origPending[$index] );
}
- $executeReqs = array();
+ $executeReqs = [];
// Services can also replace requests with new ones, either to
// defer the original or to set a proxy response to the original.
// Any replacement requests executed above will need to be replaced
// with new requests (eventually the original). The responses can be
// forced by setting 'response' rather than actually be sent over the wire.
- $newReplaceReqsByService = array();
+ $newReplaceReqsByService = [];
foreach ( $checkReqIndexesByPrefix as $prefix => $servReqIndexes ) {
$service = $this->instances[$prefix];
// $doneReqs actually has the requests (with 'response' set)
$replaceReqsByService = $newReplaceReqsByService;
} while ( count( $origPending ) );
- $responses = array();
+ $responses = [];
// Update $reqs to include 'response' and normalized request 'headers'.
// This maintains the original order of $reqs.
foreach ( $reqs as $origIndex => $req ) {