PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/s3/Aws/Middleware.php +29 -12 1.2.13 → 1.4.2 View file →
@@ -28,14 +28,28 @@
28 28 */
29 29 public static function sourceFile(Service $api, $bodyParameter = 'Body', $sourceParameter = 'SourceFile')
30 30 {
31 31 return function (callable $handler) use($api, $bodyParameter, $sourceParameter) {
32 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $api, $bodyParameter, $sourceParameter) {
32 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $api, $bodyParameter, $sourceParameter) {
33 33 $operation = $api->getOperation($command->getName());
34 34 $source = $command[$sourceParameter];
35 35 if ($source !== null && $operation->getInput()->hasMember($bodyParameter)) {
36 - $command[$bodyParameter] = new LazyOpenStream($source, 'r');
36 + $lazyOpenStream = new LazyOpenStream($source, 'r');
37 + $command[$bodyParameter] = $lazyOpenStream;
37 38 unset($command[$sourceParameter]);
39 + $next = $handler($command, $request);
40 + // To avoid failures in some tests cases
41 + if ($next !== null && \method_exists($next, 'then')) {
42 + return $next->then(function ($result) use($lazyOpenStream) {
43 + // To make sure the resource is closed.
44 + $lazyOpenStream->close();
45 + return $result;
46 + })->otherwise(function (\Throwable $e) use($lazyOpenStream) {
47 + $lazyOpenStream->close();
48 + throw $e;
49 + });
50 + }
51 + return $next;
38 52 }
39 53 return $handler($command, $request);
40 54 };
41 55 };
@@ -46,13 +60,13 @@
46 60 * @param Service $api API being accessed.
47 61 *
48 62 * @return callable
49 63 */
50 - public static function validation(Service $api, Validator $validator = null)
64 + public static function validation(Service $api, ?Validator $validator = null)
51 65 {
52 66 $validator = $validator ?: new Validator();
53 67 return function (callable $handler) use($api, $validator) {
54 - return function (CommandInterface $command, RequestInterface $request = null) use($api, $validator, $handler) {
68 + return function (CommandInterface $command, ?RequestInterface $request = null) use($api, $validator, $handler) {
55 69 if ($api->isModifiedModel()) {
56 70 $api = new Service($api->getDefinition(), $api->getProvider());
57 71 }
58 72 $operation = $api->getOperation($command->getName());
@@ -96,8 +110,9 @@
96 110 return function (CommandInterface $command, RequestInterface $request) use($handler, $signatureFunction, $credProvider, $tokenProvider, $config) {
97 111 $signer = $signatureFunction($command);
98 112 if ($signer instanceof TokenAuthorization) {
99 113 return $tokenProvider()->then(function (TokenInterface $token) use($handler, $command, $signer, $request) {
114 + $command->getMetricsBuilder()->identifyMetricByValueAndAppend('token', $token);
100 115 return $handler($command, $signer->authorizeRequest($request, $token));
101 116 });
102 117 }
103 118 if ($signer instanceof S3ExpressSignature) {
@@ -105,8 +120,10 @@
105 120 } else {
106 121 $credentialPromise = $credProvider();
107 122 }
108 123 return $credentialPromise->then(function (CredentialsInterface $creds) use($handler, $command, $signer, $request) {
124 + // Capture credentials metric
125 + $command->getMetricsBuilder()->identifyMetricByValueAndAppend('credentials', $creds);
109 126 return $handler($command, $signer->signRequest($request, $creds));
110 127 });
111 128 };
112 129 };
@@ -125,9 +142,9 @@
125 142 */
126 143 public static function tap(callable $fn)
127 144 {
128 145 return function (callable $handler) use($fn) {
129 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $fn) {
146 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $fn) {
130 147 $fn($command, $request);
131 148 return $handler($command, $request);
132 149 };
133 150 };
@@ -148,9 +165,9 @@
148 165 * associated delay.
149 166 *
150 167 * @return callable
151 168 */
152 - public static function retry(callable $decider = null, callable $delay = null, $stats = \false)
169 + public static function retry(?callable $decider = null, ?callable $delay = null, $stats = \false)
153 170 {
154 171 $decider = $decider ?: RetryMiddleware::createDefaultDecider();
155 172 $delay = $delay ?: [RetryMiddleware::class, 'exponentialDelay'];
156 173 return function (callable $handler) use($decider, $delay, $stats) {
@@ -186,9 +203,9 @@
186 203 */
187 204 public static function contentType(array $operations)
188 205 {
189 206 return function (callable $handler) use($operations) {
190 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $operations) {
207 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $operations) {
191 208 if (!$request->hasHeader('Content-Type') && \in_array($command->getName(), $operations, \true) && ($uri = $request->getBody()->getMetadata('uri'))) {
192 209 $request = $request->withHeader('Content-Type', Psr7\MimeType::fromFilename($uri) ?: 'application/octet-stream');
193 210 }
194 211 return $handler($command, $request);
@@ -236,9 +253,9 @@
236 253 */
237 254 public static function history(History $history)
238 255 {
239 256 return function (callable $handler) use($history) {
240 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $history) {
257 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $history) {
241 258 $ticket = $history->start($command, $request);
242 259 return $handler($command, $request)->then(function ($result) use($history, $ticket) {
243 260 $history->finish($ticket, $result);
244 261 return $result;
@@ -260,9 +277,9 @@
260 277 */
261 278 public static function mapRequest(callable $f)
262 279 {
263 280 return function (callable $handler) use($f) {
264 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $f) {
281 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $f) {
265 282 return $handler($command, $f($request));
266 283 };
267 284 };
268 285 }
@@ -277,9 +294,9 @@
277 294 */
278 295 public static function mapCommand(callable $f)
279 296 {
280 297 return function (callable $handler) use($f) {
281 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $f) {
298 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $f) {
282 299 return $handler($f($command), $request);
283 300 };
284 301 };
285 302 }
@@ -293,9 +310,9 @@
293 310 */
294 311 public static function mapResult(callable $f)
295 312 {
296 313 return function (callable $handler) use($f) {
297 - return function (CommandInterface $command, RequestInterface $request = null) use($handler, $f) {
314 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, $f) {
298 315 return $handler($command, $request)->then($f);
299 316 };
300 317 };
301 318 }
@@ -301,9 +318,9 @@
301 318 }
302 319 public static function timer()
303 320 {
304 321 return function (callable $handler) {
305 - return function (CommandInterface $command, RequestInterface $request = null) use($handler) {
322 + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler) {
306 323 $start = \microtime(\true);
307 324 return $handler($command, $request)->then(function (ResultInterface $res) use($start) {
308 325 if (!isset($res['@metadata'])) {
309 326 $res['@metadata'] = [];