Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/AWS/Aws/S3/S3Client.php
Строк: 1192
<?php
namespace AwsS3;

use 
AwsApiApiProvider;
use 
AwsApiDocModel;
use 
AwsApiService;
use 
AwsAwsClient;
use 
AwsCacheInterface;
use 
AwsClientResolver;
use 
AwsCommand;
use 
AwsExceptionAwsException;
use 
AwsHandlerList;
use 
AwsMiddleware;
use 
AwsRetryQuotaManager;
use 
AwsRetryMiddleware;
use 
AwsResultInterface;
use 
AwsCommandInterface;
use 
AwsRetryMiddlewareV2;
use 
AwsS3UseArnRegionConfiguration;
use 
AwsS3UseArnRegionConfigurationInterface;
use 
AwsS3UseArnRegionConfigurationProvider as UseArnRegionConfigurationProvider;
use 
AwsS3RegionalEndpointConfigurationProvider;
use 
GuzzleHttpExceptionRequestException;
use 
GuzzleHttpPromisePromise;
use 
GuzzleHttpPromisePromiseInterface;
use 
PsrHttpMessageRequestInterface;

/**
 * Client used to interact with **Amazon Simple Storage Service (Amazon S3)**.
 *
 * @method AwsResult abortMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise abortMultipartUploadAsync(array $args = [])
 * @method AwsResult completeMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise completeMultipartUploadAsync(array $args = [])
 * @method AwsResult copyObject(array $args = [])
 * @method GuzzleHttpPromisePromise copyObjectAsync(array $args = [])
 * @method AwsResult createBucket(array $args = [])
 * @method GuzzleHttpPromisePromise createBucketAsync(array $args = [])
 * @method AwsResult createMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise createMultipartUploadAsync(array $args = [])
 * @method AwsResult deleteBucket(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketAsync(array $args = [])
 * @method AwsResult deleteBucketAnalyticsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketAnalyticsConfigurationAsync(array $args = [])
 * @method AwsResult deleteBucketCors(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketCorsAsync(array $args = [])
 * @method AwsResult deleteBucketEncryption(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketEncryptionAsync(array $args = [])
 * @method AwsResult deleteBucketInventoryConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketInventoryConfigurationAsync(array $args = [])
 * @method AwsResult deleteBucketLifecycle(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketLifecycleAsync(array $args = [])
 * @method AwsResult deleteBucketMetricsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketMetricsConfigurationAsync(array $args = [])
 * @method AwsResult deleteBucketPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketPolicyAsync(array $args = [])
 * @method AwsResult deleteBucketReplication(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketReplicationAsync(array $args = [])
 * @method AwsResult deleteBucketTagging(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketTaggingAsync(array $args = [])
 * @method AwsResult deleteBucketWebsite(array $args = [])
 * @method GuzzleHttpPromisePromise deleteBucketWebsiteAsync(array $args = [])
 * @method AwsResult deleteObject(array $args = [])
 * @method GuzzleHttpPromisePromise deleteObjectAsync(array $args = [])
 * @method AwsResult deleteObjectTagging(array $args = [])
 * @method GuzzleHttpPromisePromise deleteObjectTaggingAsync(array $args = [])
 * @method AwsResult deleteObjects(array $args = [])
 * @method GuzzleHttpPromisePromise deleteObjectsAsync(array $args = [])
 * @method AwsResult deletePublicAccessBlock(array $args = [])
 * @method GuzzleHttpPromisePromise deletePublicAccessBlockAsync(array $args = [])
 * @method AwsResult getBucketAccelerateConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketAccelerateConfigurationAsync(array $args = [])
 * @method AwsResult getBucketAcl(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketAclAsync(array $args = [])
 * @method AwsResult getBucketAnalyticsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketAnalyticsConfigurationAsync(array $args = [])
 * @method AwsResult getBucketCors(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketCorsAsync(array $args = [])
 * @method AwsResult getBucketEncryption(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketEncryptionAsync(array $args = [])
 * @method AwsResult getBucketInventoryConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketInventoryConfigurationAsync(array $args = [])
 * @method AwsResult getBucketLifecycle(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketLifecycleAsync(array $args = [])
 * @method AwsResult getBucketLifecycleConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketLifecycleConfigurationAsync(array $args = [])
 * @method AwsResult getBucketLocation(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketLocationAsync(array $args = [])
 * @method AwsResult getBucketLogging(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketLoggingAsync(array $args = [])
 * @method AwsResult getBucketMetricsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketMetricsConfigurationAsync(array $args = [])
 * @method AwsResult getBucketNotification(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketNotificationAsync(array $args = [])
 * @method AwsResult getBucketNotificationConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketNotificationConfigurationAsync(array $args = [])
 * @method AwsResult getBucketPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketPolicyAsync(array $args = [])
 * @method AwsResult getBucketPolicyStatus(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketPolicyStatusAsync(array $args = [])
 * @method AwsResult getBucketReplication(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketReplicationAsync(array $args = [])
 * @method AwsResult getBucketRequestPayment(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketRequestPaymentAsync(array $args = [])
 * @method AwsResult getBucketTagging(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketTaggingAsync(array $args = [])
 * @method AwsResult getBucketVersioning(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketVersioningAsync(array $args = [])
 * @method AwsResult getBucketWebsite(array $args = [])
 * @method GuzzleHttpPromisePromise getBucketWebsiteAsync(array $args = [])
 * @method AwsResult getObject(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectAsync(array $args = [])
 * @method AwsResult getObjectAcl(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectAclAsync(array $args = [])
 * @method AwsResult getObjectLegalHold(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectLegalHoldAsync(array $args = [])
 * @method AwsResult getObjectLockConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectLockConfigurationAsync(array $args = [])
 * @method AwsResult getObjectRetention(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectRetentionAsync(array $args = [])
 * @method AwsResult getObjectTagging(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectTaggingAsync(array $args = [])
 * @method AwsResult getObjectTorrent(array $args = [])
 * @method GuzzleHttpPromisePromise getObjectTorrentAsync(array $args = [])
 * @method AwsResult getPublicAccessBlock(array $args = [])
 * @method GuzzleHttpPromisePromise getPublicAccessBlockAsync(array $args = [])
 * @method AwsResult headBucket(array $args = [])
 * @method GuzzleHttpPromisePromise headBucketAsync(array $args = [])
 * @method AwsResult headObject(array $args = [])
 * @method GuzzleHttpPromisePromise headObjectAsync(array $args = [])
 * @method AwsResult listBucketAnalyticsConfigurations(array $args = [])
 * @method GuzzleHttpPromisePromise listBucketAnalyticsConfigurationsAsync(array $args = [])
 * @method AwsResult listBucketInventoryConfigurations(array $args = [])
 * @method GuzzleHttpPromisePromise listBucketInventoryConfigurationsAsync(array $args = [])
 * @method AwsResult listBucketMetricsConfigurations(array $args = [])
 * @method GuzzleHttpPromisePromise listBucketMetricsConfigurationsAsync(array $args = [])
 * @method AwsResult listBuckets(array $args = [])
 * @method GuzzleHttpPromisePromise listBucketsAsync(array $args = [])
 * @method AwsResult listMultipartUploads(array $args = [])
 * @method GuzzleHttpPromisePromise listMultipartUploadsAsync(array $args = [])
 * @method AwsResult listObjectVersions(array $args = [])
 * @method GuzzleHttpPromisePromise listObjectVersionsAsync(array $args = [])
 * @method AwsResult listObjects(array $args = [])
 * @method GuzzleHttpPromisePromise listObjectsAsync(array $args = [])
 * @method AwsResult listObjectsV2(array $args = [])
 * @method GuzzleHttpPromisePromise listObjectsV2Async(array $args = [])
 * @method AwsResult listParts(array $args = [])
 * @method GuzzleHttpPromisePromise listPartsAsync(array $args = [])
 * @method AwsResult putBucketAccelerateConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketAccelerateConfigurationAsync(array $args = [])
 * @method AwsResult putBucketAcl(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketAclAsync(array $args = [])
 * @method AwsResult putBucketAnalyticsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketAnalyticsConfigurationAsync(array $args = [])
 * @method AwsResult putBucketCors(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketCorsAsync(array $args = [])
 * @method AwsResult putBucketEncryption(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketEncryptionAsync(array $args = [])
 * @method AwsResult putBucketInventoryConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketInventoryConfigurationAsync(array $args = [])
 * @method AwsResult putBucketLifecycle(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketLifecycleAsync(array $args = [])
 * @method AwsResult putBucketLifecycleConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketLifecycleConfigurationAsync(array $args = [])
 * @method AwsResult putBucketLogging(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketLoggingAsync(array $args = [])
 * @method AwsResult putBucketMetricsConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketMetricsConfigurationAsync(array $args = [])
 * @method AwsResult putBucketNotification(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketNotificationAsync(array $args = [])
 * @method AwsResult putBucketNotificationConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketNotificationConfigurationAsync(array $args = [])
 * @method AwsResult putBucketPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketPolicyAsync(array $args = [])
 * @method AwsResult putBucketReplication(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketReplicationAsync(array $args = [])
 * @method AwsResult putBucketRequestPayment(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketRequestPaymentAsync(array $args = [])
 * @method AwsResult putBucketTagging(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketTaggingAsync(array $args = [])
 * @method AwsResult putBucketVersioning(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketVersioningAsync(array $args = [])
 * @method AwsResult putBucketWebsite(array $args = [])
 * @method GuzzleHttpPromisePromise putBucketWebsiteAsync(array $args = [])
 * @method AwsResult putObject(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectAsync(array $args = [])
 * @method AwsResult putObjectAcl(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectAclAsync(array $args = [])
 * @method AwsResult putObjectLegalHold(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectLegalHoldAsync(array $args = [])
 * @method AwsResult putObjectLockConfiguration(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectLockConfigurationAsync(array $args = [])
 * @method AwsResult putObjectRetention(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectRetentionAsync(array $args = [])
 * @method AwsResult putObjectTagging(array $args = [])
 * @method GuzzleHttpPromisePromise putObjectTaggingAsync(array $args = [])
 * @method AwsResult putPublicAccessBlock(array $args = [])
 * @method GuzzleHttpPromisePromise putPublicAccessBlockAsync(array $args = [])
 * @method AwsResult restoreObject(array $args = [])
 * @method GuzzleHttpPromisePromise restoreObjectAsync(array $args = [])
 * @method AwsResult selectObjectContent(array $args = [])
 * @method GuzzleHttpPromisePromise selectObjectContentAsync(array $args = [])
 * @method AwsResult uploadPart(array $args = [])
 * @method GuzzleHttpPromisePromise uploadPartAsync(array $args = [])
 * @method AwsResult uploadPartCopy(array $args = [])
 * @method GuzzleHttpPromisePromise uploadPartCopyAsync(array $args = [])
 */
class S3Client extends AwsClient implements S3ClientInterface
{
    use 
S3ClientTrait;

    public static function 
getArguments()
    {
        
$args parent::getArguments();
        
$args['retries']['fn'] = [__CLASS__'_applyRetryConfig'];
        
$args['api_provider']['fn'] = [__CLASS__'_applyApiProvider'];

        return 
$args + [
            
'bucket_endpoint' => [
                
'type'    => 'config',
                
'valid'   => ['bool'],
                
'doc'     => 'Set to true to send requests to a hardcoded '
                    
'bucket endpoint rather than create an endpoint as a '
                    
'result of injecting the bucket into the URL. This '
                    
'option is useful for interacting with CNAME endpoints.',
            ],
            
'use_arn_region' => [
                
'type'    => 'config',
                
'valid'   => [
                    
'bool',
                    
Configuration::class,
                    
CacheInterface::class,
                    
'callable'
                
],
                
'doc'     => 'Set to true to allow passed in ARNs to override'
                    
' client region. Accepts...',
                
'fn' => [__CLASS__'_apply_use_arn_region'],
                
'default' => [UseArnRegionConfigurationProvider::class, 'defaultProvider'],
            ],
            
'use_accelerate_endpoint' => [
                
'type' => 'config',
                
'valid' => ['bool'],
                
'doc' => 'Set to true to send requests to an S3 Accelerate'
                    
' endpoint by default. Can be enabled or disabled on'
                    
' individual operations by setting'
                    
' '@use_accelerate_endpoint' to true or false. Note:'
                    
' you must enable S3 Accelerate on a bucket before it can'
                    
' be accessed via an Accelerate endpoint.',
                
'default' => false,
            ],
            
'use_dual_stack_endpoint' => [
                
'type' => 'config',
                
'valid' => ['bool'],
                
'doc' => 'Set to true to send requests to an S3 Dual Stack'
                    
' endpoint by default, which enables IPv6 Protocol.'
                    
' Can be enabled or disabled on individual operations by setting'
                    
' '@use_dual_stack_endpoint' to true or false.',
                
'default' => false,
            ],
            
'use_path_style_endpoint' => [
                
'type' => 'config',
                
'valid' => ['bool'],
                
'doc' => 'Set to true to send requests to an S3 path style'
                    
' endpoint by default.'
                    
' Can be enabled or disabled on individual operations by setting'
                    
' '@use_path_style_endpoint' to true or false.',
                
'default' => false,
            ],
        ];
    }

    
/**
     * {@inheritdoc}
     *
     * In addition to the options available to
     * {@see AwsAwsClient::__construct}, S3Client accepts the following
     * options:
     *
     * - bucket_endpoint: (bool) Set to true to send requests to a
     *   hardcoded bucket endpoint rather than create an endpoint as a result
     *   of injecting the bucket into the URL. This option is useful for
     *   interacting with CNAME endpoints.
     * - calculate_md5: (bool) Set to false to disable calculating an MD5
     *   for all Amazon S3 signed uploads.
     * - s3_us_east_1_regional_endpoint:
     *   (AwsS3RegionalEndpointConfigurationInterface|AwsCacheInterface|callable|string|array)
     *   Specifies whether to use regional or legacy endpoints for the us-east-1
     *   region. Provide an AwsS3RegionalEndpointConfigurationInterface object, an
     *   instance of AwsCacheInterface, a callable configuration provider used
     *   to create endpoint configuration, a string value of `legacy` or
     *   `regional`, or an associative array with the following keys:
     *   endpoint_types: (string)  Set to `legacy` or `regional`, defaults to
     *   `legacy`
     * - use_accelerate_endpoint: (bool) Set to true to send requests to an S3
     *   Accelerate endpoint by default. Can be enabled or disabled on
     *   individual operations by setting '@use_accelerate_endpoint' to true or
     *   false. Note: you must enable S3 Accelerate on a bucket before it can be
     *   accessed via an Accelerate endpoint.
     * - use_arn_region: (AwsS3UseArnRegionConfigurationInterface,
     *   AwsCacheInterface, bool, callable) Set to true to enable the client
     *   to use the region from a supplied ARN argument instead of the client's
     *   region. Provide an instance of AwsS3UseArnRegionConfigurationInterface,
     *   an instance of AwsCacheInterface, a callable that provides a promise for
     *   a Configuration object, or a boolean value. Defaults to false (i.e.
     *   the SDK will not follow the ARN region if it conflicts with the client
     *   region and instead throw an error).
     * - use_dual_stack_endpoint: (bool) Set to true to send requests to an S3
     *   Dual Stack endpoint by default, which enables IPv6 Protocol.
     *   Can be enabled or disabled on individual operations by setting
     *   '@use_dual_stack_endpoint' to true or false. Note:
     *   you cannot use it together with an accelerate endpoint.
     * - use_path_style_endpoint: (bool) Set to true to send requests to an S3
     *   path style endpoint by default.
     *   Can be enabled or disabled on individual operations by setting
     *   '@use_path_style_endpoint' to true or false. Note:
     *   you cannot use it together with an accelerate endpoint.
     *
     * @param array $args
     */
    
public function __construct(array $args)
    {
        if (!isset(
$args['s3_us_east_1_regional_endpoint'])) {
            
$args['s3_us_east_1_regional_endpoint'] = ConfigurationProvider::defaultProvider();
        } elseif (
$args['s3_us_east_1_regional_endpoint'] instanceof CacheInterface) {
            
$args['s3_us_east_1_regional_endpoint'] = ConfigurationProvider::defaultProvider($args);
        }
        
parent::__construct($args);
        
$stack $this->getHandlerList();
        
$stack->appendInit(SSECMiddleware::wrap($this->getEndpoint()->getScheme()), 's3.ssec');
        
$stack->appendBuild(ApplyChecksumMiddleware::wrap($this->getApi()), 's3.checksum');
        
$stack->appendBuild(
            
Middleware::contentType(['PutObject''UploadPart']),
            
's3.content_type'
        
);

        
// Use the bucket style middleware when using a "bucket_endpoint" (for cnames)
        
if ($this->getConfig('bucket_endpoint')) {
            
$stack->appendBuild(BucketEndpointMiddleware::wrap(), 's3.bucket_endpoint');
        } else {
            
$stack->appendBuild(
                
S3EndpointMiddleware::wrap(
                    
$this->getRegion(),
                    
$this->getConfig('endpoint_provider'),
                    [
                        
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
                        
'accelerate' => $this->getConfig('use_accelerate_endpoint'),
                        
'path_style' => $this->getConfig('use_path_style_endpoint')
                    ]
                ),
                
's3.endpoint_middleware'
            
);
        }

        
$stack->appendBuild(
            
BucketEndpointArnMiddleware::wrap(
                
$this->getApi(),
                
$this->getRegion(),
                [
                    
'use_arn_region' => $this->getConfig('use_arn_region'),
                    
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
                    
'accelerate' => $this->getConfig('use_accelerate_endpoint'),
                    
'path_style' => $this->getConfig('use_path_style_endpoint'),
                    
'endpoint' => isset($args['endpoint'])
                        ? 
$args['endpoint']
                        : 
null
                
]
            ),
            
's3.bucket_endpoint_arn'
        
);
        
$stack->appendSign(PutObjectUrlMiddleware::wrap(), 's3.put_object_url');
        
$stack->appendSign(PermanentRedirectMiddleware::wrap(), 's3.permanent_redirect');
        
$stack->appendInit(Middleware::sourceFile($this->getApi()), 's3.source_file');
        
$stack->appendInit($this->getSaveAsParameter(), 's3.save_as');
        
$stack->appendInit($this->getLocationConstraintMiddleware(), 's3.location');
        
$stack->appendInit($this->getEncodingTypeMiddleware(), 's3.auto_encode');
        
$stack->appendInit($this->getHeadObjectMiddleware(), 's3.head_object');
    }

    
/**
     * Determine if a string is a valid name for a DNS compatible Amazon S3
     * bucket.
     *
     * DNS compatible bucket names can be used as a subdomain in a URL (e.g.,
     * "<bucket>.s3.amazonaws.com").
     *
     * @param string $bucket Bucket name to check.
     *
     * @return bool
     */
    
public static function isBucketDnsCompatible($bucket)
    {
        
$bucketLen strlen($bucket);

        return (
$bucketLen >= && $bucketLen <= 63) &&
            
// Cannot look like an IP address
            
!filter_var($bucketFILTER_VALIDATE_IP) &&
            
preg_match('/^[a-z0-9]([a-z0-9-.]*[a-z0-9])?$/'$bucket);
    }

    public static function 
_apply_use_arn_region($value, array &$argsHandlerList $list)
    {
        if (
$value instanceof CacheInterface) {
            
$value UseArnRegionConfigurationProvider::defaultProvider($args);
        }
        if (
is_callable($value)) {
            
$value $value();
        }
        if (
$value instanceof PromiseInterface) {
            
$value $value->wait();
        }
        if (
$value instanceof ConfigurationInterface) {
            
$args['use_arn_region'] = $value;
        } else {
            
// The Configuration class itself will validate other inputs
            
$args['use_arn_region'] = new Configuration($value);
        }
    }

    public function 
createPresignedRequest(CommandInterface $command$expires, array $options = [])
    {
        
$command = clone $command;
        
$command->getHandlerList()->remove('signer');

        
/** @var AwsSignatureSignatureInterface $signer */
        
$signer call_user_func(
            
$this->getSignatureProvider(),
            
$this->getConfig('signature_version'),
            
$this->getConfig('signing_name'),
            
$this->getConfig('signing_region')
        );

        return 
$signer->presign(
            
Awsserialize($command),
            
$this->getCredentials()->wait(),
            
$expires,
            
$options
        
);
    }

    
/**
     * Returns the URL to an object identified by its bucket and key.
     *
     * The URL returned by this method is not signed nor does it ensure that the
     * bucket and key given to the method exist. If you need a signed URL, then
     * use the {@see AwsS3S3Client::createPresignedRequest} method and get
     * the URI of the signed request.
     *
     * @param string $bucket  The name of the bucket where the object is located
     * @param string $key     The key of the object
     *
     * @return string The URL to the object
     */
    
public function getObjectUrl($bucket$key)
    {
        
$command $this->getCommand('GetObject', [
            
'Bucket' => $bucket,
            
'Key'    => $key
        
]);

        return (string) 
Awsserialize($command)->getUri();
    }

    
/**
     * Raw URL encode a key and allow for '/' characters
     *
     * @param string $key Key to encode
     *
     * @return string Returns the encoded key
     */
    
public static function encodeKey($key)
    {
        return 
str_replace('%2F''/'rawurlencode($key));
    }

    
/**
     * Provides a middleware that removes the need to specify LocationConstraint on CreateBucket.
     *
     * @return Closure
     */
    
private function getLocationConstraintMiddleware()
    {
        
$region $this->getRegion();
        return static function (callable 
$handler) use ($region) {
            return function (
Command $command$request null) use ($handler$region) {
                if (
$command->getName() === 'CreateBucket') {
                    
$locationConstraint = isset($command['CreateBucketConfiguration']['LocationConstraint'])
                        ? 
$command['CreateBucketConfiguration']['LocationConstraint']
                        : 
null;

                    if (
$locationConstraint === 'us-east-1') {
                        unset(
$command['CreateBucketConfiguration']);
                    } elseif (
'us-east-1' !== $region && empty($locationConstraint)) {
                        
$command['CreateBucketConfiguration'] = ['LocationConstraint' => $region];
                    }
                }

                return 
$handler($command$request);
            };
        };
    }

    
/**
     * Provides a middleware that supports the `SaveAs` parameter.
     *
     * @return Closure
     */
    
private function getSaveAsParameter()
    {
        return static function (callable 
$handler) {
            return function (
Command $command$request null) use ($handler) {
                if (
$command->getName() === 'GetObject' && isset($command['SaveAs'])) {
                    
$command['@http']['sink'] = $command['SaveAs'];
                    unset(
$command['SaveAs']);
                }

                return 
$handler($command$request);
            };
        };
    }

    
/**
     * Provides a middleware that disables content decoding on HeadObject
     * commands.
     *
     * @return Closure
     */
    
private function getHeadObjectMiddleware()
    {
        return static function (callable 
$handler) {
            return function (
                
CommandInterface $command,
                
RequestInterface $request null
            
) use ($handler) {
                if (
$command->getName() === 'HeadObject'
                    
&& !isset($command['@http']['decode_content'])
                ) {
                    
$command['@http']['decode_content'] = false;
                }

                return 
$handler($command$request);
            };
        };
    }

    
/**
     * Provides a middleware that autopopulates the EncodingType parameter on
     * ListObjects commands.
     *
     * @return Closure
     */
    
private function getEncodingTypeMiddleware()
    {
        return static function (callable 
$handler) {
            return function (
Command $command$request null) use ($handler) {
                
$autoSet false;
                if (
$command->getName() === 'ListObjects'
                    
&& empty($command['EncodingType'])
                ) {
                    
$command['EncodingType'] = 'url';
                    
$autoSet true;
                }

                return 
$handler($command$request)
                    ->
then(function (ResultInterface $result) use ($autoSet) {
                        if (
$result['EncodingType'] === 'url' && $autoSet) {
                            static 
$topLevel = [
                                
'Delimiter',
                                
'Marker',
                                
'NextMarker',
                                
'Prefix',
                            ];
                            static 
$nested = [
                                [
'Contents''Key'],
                                [
'CommonPrefixes''Prefix'],
                            ];

                            foreach (
$topLevel as $key) {
                                if (isset(
$result[$key])) {
                                    
$result[$key] = urldecode($result[$key]);
                                }
                            }
                            foreach (
$nested as $steps) {
                                if (isset(
$result[$steps[0]])) {
                                    foreach (
$result[$steps[0]] as $key => $part) {
                                        if (isset(
$part[$steps[1]])) {
                                            
$result[$steps[0]][$key][$steps[1]]
                                                = 
urldecode($part[$steps[1]]);
                                        }
                                    }
                                }
                            }

                        }

                        return 
$result;
                    });
            };
        };
    }

    
/** @internal */
    
public static function _applyRetryConfig($value$argsHandlerList $list)
    {
        if (
$value) {
            
$config AwsRetryConfigurationProvider::unwrap($value);

            if (
$config->getMode() === 'legacy') {
                
$maxRetries $config->getMaxAttempts() - 1;
                
$decider RetryMiddleware::createDefaultDecider($maxRetries);
                
$decider = function ($retries$command$request$result$error) use ($decider$maxRetries) {
                    
$maxRetries null !== $command['@retries']
                        ? 
$command['@retries']
                        : 
$maxRetries;

                    if (
$decider($retries$command$request$result$error)) {
                        return 
true;
                    }

                    if (
$error instanceof AwsException
                        
&& $retries $maxRetries
                    
) {
                        if (
$error->getResponse()
                            && 
$error->getResponse()->getStatusCode() >= 400
                        
) {
                            return 
strpos(
                                    
$error->getResponse()->getBody(),
                                    
'Your socket connection to the server'
                                
) !== false;
                        }

                        if (
$error->getPrevious() instanceof RequestException) {
                            
// All commands except CompleteMultipartUpload are
                            // idempotent and may be retried without worry if a
                            // networking error has occurred.
                            
return $command->getName() !== 'CompleteMultipartUpload';
                        }
                    }

                    return 
false;
                };

                
$delay = [RetryMiddleware::class, 'exponentialDelay'];
                
$list->appendSign(Middleware::retry($decider$delay), 'retry');
            } else {
                
$defaultDecider RetryMiddlewareV2::createDefaultDecider(
                    new 
QuotaManager(),
                    
$config->getMaxAttempts()
                );

                
$list->appendSign(
                    
RetryMiddlewareV2::wrap(
                        
$config,
                        [
                            
'collect_stats' => $args['stats']['retries'],
                            
'decider' => function(
                                
$attempts,
                                
CommandInterface $cmd,
                                
$result
                            
) use ($defaultDecider$config) {
                                
$isRetryable $defaultDecider($attempts$cmd$result);
                                if (!
$isRetryable
                                    
&& $result instanceof AwsException
                                    
&& $attempts $config->getMaxAttempts()
                                ) {
                                    if (!empty(
$result->getResponse())
                                        && 
strpos(
                                            
$result->getResponse()->getBody(),
                                            
'Your socket connection to the server'
                                        
) !== false
                                    
) {
                                        
$isRetryable false;
                                    }
                                    if (
$result->getPrevious() instanceof RequestException
                                        
&& $cmd->getName() !== 'CompleteMultipartUpload'
                                    
) {
                                        
$isRetryable true;
                                    }
                                }
                                return 
$isRetryable;
                            }
                        ]
                    ),
                    
'retry'
                
);
            }
        }
    }

    
/** @internal */
    
public static function _applyApiProvider($value, array &$argsHandlerList $list)
    {
        
ClientResolver::_apply_api_provider($value$args);
        
$args['parser'] = new GetBucketLocationParser(
            new 
AmbiguousSuccessParser(
                new 
RetryableMalformedResponseParser(
                    
$args['parser'],
                    
$args['exception_class']
                ),
                
$args['error_parser'],
                
$args['exception_class']
            )
        );
    }

    
/**
     * @internal
     * @codeCoverageIgnore
     */
    
public static function applyDocFilters(array $api, array $docs)
    {
        
$b64 '<div class="alert alert-info">This value will be base64 encoded on your behalf.</div>';
        
$opt '<div class="alert alert-info">This value will be computed for you it is not supplied.</div>';

        
// Add the SourceFile parameter.
        
$docs['shapes']['SourceFile']['base'] = 'The path to a file on disk to use instead of the Body parameter.';
        
$api['shapes']['SourceFile'] = ['type' => 'string'];
        
$api['shapes']['PutObjectRequest']['members']['SourceFile'] = ['shape' => 'SourceFile'];
        
$api['shapes']['UploadPartRequest']['members']['SourceFile'] = ['shape' => 'SourceFile'];

        
// Add the ContentSHA256 parameter.
        
$docs['shapes']['ContentSHA256']['base'] = 'A SHA256 hash of the body content of the request.';
        
$api['shapes']['ContentSHA256'] = ['type' => 'string'];
        
$api['shapes']['PutObjectRequest']['members']['ContentSHA256'] = ['shape' => 'ContentSHA256'];
        
$api['shapes']['UploadPartRequest']['members']['ContentSHA256'] = ['shape' => 'ContentSHA256'];
        unset(
$api['shapes']['PutObjectRequest']['members']['ContentMD5']);
        unset(
$api['shapes']['UploadPartRequest']['members']['ContentMD5']);
        
$docs['shapes']['ContentSHA256']['append'] = $opt;

        
// Add the SaveAs parameter.
        
$docs['shapes']['SaveAs']['base'] = 'The path to a file on disk to save the object data.';
        
$api['shapes']['SaveAs'] = ['type' => 'string'];
        
$api['shapes']['GetObjectRequest']['members']['SaveAs'] = ['shape' => 'SaveAs'];

        
// Several SSECustomerKey documentation updates.
        
$docs['shapes']['SSECustomerKey']['append'] = $b64;
        
$docs['shapes']['CopySourceSSECustomerKey']['append'] = $b64;
        
$docs['shapes']['SSECustomerKeyMd5']['append'] = $opt;

        
// Add the ObjectURL to various output shapes and documentation.
        
$docs['shapes']['ObjectURL']['base'] = 'The URI of the created object.';
        
$api['shapes']['ObjectURL'] = ['type' => 'string'];
        
$api['shapes']['PutObjectOutput']['members']['ObjectURL'] = ['shape' => 'ObjectURL'];
        
$api['shapes']['CopyObjectOutput']['members']['ObjectURL'] = ['shape' => 'ObjectURL'];
        
$api['shapes']['CompleteMultipartUploadOutput']['members']['ObjectURL'] = ['shape' => 'ObjectURL'];

        
// Fix references to Location Constraint.
        
unset($api['shapes']['CreateBucketRequest']['payload']);
        
$api['shapes']['BucketLocationConstraint']['enum'] = [
            
"ap-northeast-1",
            
"ap-southeast-2",
            
"ap-southeast-1",
            
"cn-north-1",
            
"eu-central-1",
            
"eu-west-1",
            
"us-east-1",
            
"us-west-1",
            
"us-west-2",
            
"sa-east-1",
        ];

        
// Add a note that the ContentMD5 is optional.
        
$docs['shapes']['ContentMD5']['append'] = '<div class="alert alert-info">The value will be computed on '
            
'your behalf.</div>';

        return [
            new 
Service($apiApiProvider::defaultProvider()),
            new 
DocModel($docs)
        ];
    }

    
/**
     * @internal
     * @codeCoverageIgnore
     */
    
public static function addDocExamples($examples)
    {
        
$getObjectExample = [
            
'input' => [
                
'Bucket' => 'arn:aws:s3:us-east-1:123456789012:accesspoint:myaccesspoint',
                
'Key' => 'my-key'
            
],
            
'output' => [
                
'Body' => 'class GuzzleHttpPsr7Stream#208 (7) {...}',
                
'ContentLength' => '11',
                
'ContentType' => 'application/octet-stream',
            ],
            
'comments' => [
                
'input' => '',
                
'output' => 'Simplified example output'
            
],
            
'description' => 'The following example retrieves an object by referencing the bucket via an S3 accesss point ARN. Result output is simplified for the example.',
            
'id' => '',
            
'title' => 'To get an object via an S3 access point ARN'
        
];
        if (isset(
$examples['GetObject'])) {
            
$examples['GetObject'] []= $getObjectExample;
        } else {
            
$examples['GetObject'] = [$getObjectExample];
        }

        
$putObjectExample = [
            
'input' => [
                
'Bucket' => 'arn:aws:s3:us-east-1:123456789012:accesspoint:myaccesspoint',
                
'Key' => 'my-key',
                
'Body' => 'my-body',
            ],
            
'output' => [
                
'ObjectURL' => 'https://my-bucket.s3.us-east-1.amazonaws.com/my-key'
            
],
            
'comments' => [
                
'input' => '',
                
'output' => 'Simplified example output'
            
],
            
'description' => 'The following example uploads an object by referencing the bucket via an S3 accesss point ARN. Result output is simplified for the example.',
            
'id' => '',
            
'title' => 'To upload an object via an S3 access point ARN'
        
];
        if (isset(
$examples['PutObject'])) {
            
$examples['PutObject'] []= $putObjectExample;
        } else {
            
$examples['PutObject'] = [$putObjectExample];
        }

        return 
$examples;
    }
}
Онлайн: 0
Реклама