# media-cloud-sync/1.2.0/includes/sdk/s3/Aws/S3/PutObjectUrlMiddleware.php

Media Cloud Sync, version 1.2.0. 53 lines.

- Page: https://pluginprobe.com/plugins/media-cloud-sync/1.2.0/code/includes/sdk/s3/Aws/S3/PutObjectUrlMiddleware.php
- Raw: https://pluginprobe.com/plugins/media-cloud-sync/1.2.0/raw/includes/sdk/s3/Aws/S3/PutObjectUrlMiddleware.php
- Modified: 2024-10-27T10:40:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/media-cloud-sync/1.2.0/code/includes/sdk/s3/Aws/S3/PutObjectUrlMiddleware.php#L10-L20`.

```php
<?php

namespace Dudlewebs\WPMCS\s3\Aws\S3;

use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
use Dudlewebs\WPMCS\s3\Aws\ResultInterface;
use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
/**
 * Injects ObjectURL into the result of the PutObject operation.
 *
 * @internal
 */
class PutObjectUrlMiddleware
{
    /** @var callable  */
    private $nextHandler;
    /**
     * Create a middleware wrapper function.
     *
     * @return callable
     */
    public static function wrap()
    {
        return function (callable $handler) {
            return new self($handler);
        };
    }
    /**
     * @param callable $nextHandler Next handler to invoke.
     */
    public function __construct(callable $nextHandler)
    {
        $this->nextHandler = $nextHandler;
    }
    public function __invoke(CommandInterface $command, RequestInterface $request = null)
    {
        $next = $this->nextHandler;
        return $next($command, $request)->then(function (ResultInterface $result) use($command) {
            $name = $command->getName();
            switch ($name) {
                case 'PutObject':
                case 'CopyObject':
                    $result['ObjectURL'] = isset($result['@metadata']['effectiveUri']) ? $result['@metadata']['effectiveUri'] : null;
                    break;
                case 'CompleteMultipartUpload':
                    $result['ObjectURL'] = $result['Location'];
                    break;
            }
            return $result;
        });
    }
}

```
