PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / S3 / PutObjectUrlMiddleware.php

PutObjectUrlMiddleware.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/S3/PutObjectUrlMiddleware.php

53 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\S3;
4
5 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
6 use Dudlewebs\WPMCS\s3\Aws\ResultInterface;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
8 /**
9 * Injects ObjectURL into the result of the PutObject operation.
10 *
11 * @internal
12 */
13 class PutObjectUrlMiddleware
14 {
15 /** @var callable */
16 private $nextHandler;
17 /**
18 * Create a middleware wrapper function.
19 *
20 * @return callable
21 */
22 public static function wrap()
23 {
24 return function (callable $handler) {
25 return new self($handler);
26 };
27 }
28 /**
29 * @param callable $nextHandler Next handler to invoke.
30 */
31 public function __construct(callable $nextHandler)
32 {
33 $this->nextHandler = $nextHandler;
34 }
35 public function __invoke(CommandInterface $command, ?RequestInterface $request = null)
36 {
37 $next = $this->nextHandler;
38 return $next($command, $request)->then(function (ResultInterface $result) use($command) {
39 $name = $command->getName();
40 switch ($name) {
41 case 'PutObject':
42 case 'CopyObject':
43 $result['ObjectURL'] = isset($result['@metadata']['effectiveUri']) ? $result['@metadata']['effectiveUri'] : null;
44 break;
45 case 'CompleteMultipartUpload':
46 $result['ObjectURL'] = \urldecode($result['Location'] ?? '');
47 break;
48 }
49 return $result;
50 });
51 }
52 }
53