X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Fvirtualrest%2FSwiftVirtualRESTService.php;h=e00bee36a82a3635924a7e2850d435911ad4d869;hb=369b3fa977a2d5ce07ed14b9b54f30c8803f6b1a;hp=011dabe080f28467e1e5a48e37b8be805b0914c1;hpb=94c8c3bdd94bdc32e1dce900cbf45ce2f634dfc0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/virtualrest/SwiftVirtualRESTService.php b/includes/libs/virtualrest/SwiftVirtualRESTService.php index 011dabe080..e00bee36a8 100644 --- a/includes/libs/virtualrest/SwiftVirtualRESTService.php +++ b/includes/libs/virtualrest/SwiftVirtualRESTService.php @@ -22,7 +22,7 @@ /** * Example virtual rest service for OpenStack Swift - * @TODO: caching support (APC/memcached) + * @todo caching support (APC/memcached) * @since 1.23 */ class SwiftVirtualRESTService extends VirtualRESTService { @@ -45,7 +45,11 @@ class SwiftVirtualRESTService extends VirtualRESTService { * - swiftAuthTTL : Swift authentication TTL (seconds) */ public function __construct( array $params ) { - parent::__construct( $params ); + // set up defaults and merge them with the given params + $mparams = array_merge( [ + 'name' => 'swift' + ], $params ); + parent::__construct( $mparams ); } /** @@ -70,10 +74,10 @@ class SwiftVirtualRESTService extends VirtualRESTService { $this->authSessionTimestamp = 0; list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $req['response']; if ( $rcode >= 200 && $rcode <= 299 ) { // OK - $this->authCreds = array( + $this->authCreds = [ 'auth_token' => $rhdrs['x-auth-token'], 'storage_url' => $rhdrs['x-storage-url'] - ); + ]; $this->authSessionTimestamp = time(); return true; } elseif ( $rcode === 403 ) { @@ -90,7 +94,7 @@ class SwiftVirtualRESTService extends VirtualRESTService { } public function onRequests( array $reqs, Closure $idGeneratorFunc ) { - $result = array(); + $result = []; $firstReq = reset( $reqs ); if ( $firstReq && count( $reqs ) == 1 && isset( $firstReq['isAuth'] ) ) { // This was an authentication request for work requests... @@ -101,29 +105,29 @@ class SwiftVirtualRESTService extends VirtualRESTService { if ( $needsAuth === true ) { // These are work requests and we don't have any token to use. // Replace the work requests with an authentication request. - $result = array( - $idGeneratorFunc() => array( + $result = [ + $idGeneratorFunc() => [ 'method' => 'GET', 'url' => $this->params['swiftAuthUrl'] . "/v1.0", - 'headers' => array( + 'headers' => [ 'x-auth-user' => $this->params['swiftUser'], - 'x-auth-key' => $this->params['swiftKey'] ), + 'x-auth-key' => $this->params['swiftKey'] ], 'isAuth' => true, 'chain' => $reqs - ) - ); + ] + ]; } elseif ( $needsAuth !== false ) { // These are work requests and authentication has previously failed. // It is most efficient to just give failed pseudo responses back for // the original work requests. foreach ( $reqs as $key => $req ) { - $req['response'] = array( + $req['response'] = [ 'code' => $this->authCachedStatus, 'reason' => $this->authCachedReason, - 'headers' => array(), + 'headers' => [], 'body' => '', 'error' => '' - ); + ]; $result[$key] = $req; } } else { @@ -147,7 +151,7 @@ class SwiftVirtualRESTService extends VirtualRESTService { public function onResponses( array $reqs, Closure $idGeneratorFunc ) { $firstReq = reset( $reqs ); if ( $firstReq && count( $reqs ) == 1 && isset( $firstReq['isAuth'] ) ) { - $result = array(); + $result = []; // This was an authentication request for work requests... if ( $this->applyAuthResponse( $firstReq ) ) { // If it succeeded, we can subsitute the work requests back. @@ -157,13 +161,13 @@ class SwiftVirtualRESTService extends VirtualRESTService { // If it failed, it is most efficient to just give failing // pseudo-responses back for the actual work requests. foreach ( $firstReq['chain'] as $key => $req ) { - $req['response'] = array( + $req['response'] = [ 'code' => $this->authCachedStatus, 'reason' => $this->authCachedReason, - 'headers' => array(), + 'headers' => [], 'body' => '', 'error' => '' - ); + ]; $result[$key] = $req; } }