From 59b6b9e17e33609e3d790c3c25f2ae5b86eb3225 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Fri, 8 Dec 2023 13:18:26 +0800 Subject: [PATCH] Fix dynamic property error --- src/CommandToRequestTransformer.php | 513 ++++++++++++++-------------- src/Copy.php | 5 +- src/ExceptionMiddleware.php | 2 - src/MultipartUpload.php | 7 +- src/RangeDownload.php | 15 +- 5 files changed, 270 insertions(+), 272 deletions(-) diff --git a/src/CommandToRequestTransformer.php b/src/CommandToRequestTransformer.php index fdf32732..c5981e30 100644 --- a/src/CommandToRequestTransformer.php +++ b/src/CommandToRequestTransformer.php @@ -2,12 +2,10 @@ namespace Qcloud\Cos; -use http\Exception\BadUrlException; use Psr\Http\Message\RequestInterface; use GuzzleHttp\Command\CommandInterface; use GuzzleHttp\Psr7\Uri; use InvalidArgumentException; -use Psr\Http\Message\UriInterface; class CommandToRequestTransformer { private $config; @@ -19,7 +17,6 @@ public function __construct( $config, $operation ) { } // format bucket style - public function bucketStyleTransformer( CommandInterface $command, RequestInterface $request ) { $action = $command->getName(); if ($action == 'ListBuckets') { @@ -111,9 +108,7 @@ public function bucketStyleTransformer( CommandInterface $command, RequestInterf } // format upload body - public function uploadBodyTransformer( CommandInterface $command, $request, $bodyParameter = 'Body', $sourceParameter = 'SourceFile' ) { - $operation = $this->operation; if ( !isset( $operation['parameters']['Body'] ) ) { return $request; @@ -132,296 +127,290 @@ public function uploadBodyTransformer( CommandInterface $command, $request, $bod } } - // update md5 - - public function md5Transformer( CommandInterface $command, $request ) { - $operation = $this->operation; - if ( isset( $operation['data']['contentMd5'] ) ) { + // update md5 + public function md5Transformer( CommandInterface $command, $request ) { + $operation = $this->operation; + if ( isset( $operation['data']['contentMd5'] ) ) { + $request = $this->addMd5( $request ); + } + if ( isset( $operation['parameters']['ContentMD5'] ) && + isset( $command['ContentMD5'] ) ) { + $value = $command['ContentMD5']; + if ( $value != false ) { $request = $this->addMd5( $request ); } - if ( isset( $operation['parameters']['ContentMD5'] ) && - isset( $command['ContentMD5'] ) ) { - $value = $command['ContentMD5']; - if ( $value != false ) { - $request = $this->addMd5( $request ); - } - } - - return $request; } - // add Query string + return $request; + } - public function queryStringTransformer( CommandInterface $command, $request ) { - $operation = $this->operation; - if ( isset( $command['Params'] ) ) { - $params = $command['Params']; - foreach ( $params as $key => $value ) { - $uri = $request->getUri(); - $query = $uri->getQuery(); - $uri = $uri->withQuery($query. "&" . urlencode($key) . "=" . $value ); - $request = $request->withUri( $uri ); - } + // add Query string + public function queryStringTransformer( CommandInterface $command, $request ) { + $operation = $this->operation; + if ( isset( $command['Params'] ) ) { + $params = $command['Params']; + foreach ( $params as $key => $value ) { + $uri = $request->getUri(); + $query = $uri->getQuery(); + $uri = $uri->withQuery($query. "&" . urlencode($key) . "=" . $value ); + $request = $request->withUri( $uri ); } - - return $request; } - // add Header string + return $request; + } - public function headerTransformer( CommandInterface $command, $request ) { - $operation = $this->operation; - if ( isset( $command['Headers'] ) ) { - $headers = $command['Headers']; - foreach ( $headers as $key => $value ) { - $request = $request->withHeader( $key, $value); - } + // add Header string + public function headerTransformer( CommandInterface $command, $request ) { + $operation = $this->operation; + if ( isset( $command['Headers'] ) ) { + $headers = $command['Headers']; + foreach ( $headers as $key => $value ) { + $request = $request->withHeader( $key, $value); } - return $request; } + return $request; + } - // add meta + // add meta - public function metadataTransformer( CommandInterface $command, $request ) { - $operation = $this->operation; - if ( isset( $command['Metadata'] ) ) { - $meta = $command['Metadata']; - foreach ( $meta as $key => $value ) { - $request = $request->withHeader( 'x-cos-meta-' . $key, $value ); - } + public function metadataTransformer( CommandInterface $command, $request ) { + $operation = $this->operation; + if ( isset( $command['Metadata'] ) ) { + $meta = $command['Metadata']; + foreach ( $meta as $key => $value ) { + $request = $request->withHeader( 'x-cos-meta-' . $key, $value ); } - $request = headersMap( $command, $request ); - - return $request; } + $request = headersMap( $command, $request ); - // count md5 + return $request; + } - private function addMd5( $request ) { - $body = $request->getBody(); - if ( $body && $body->getSize() > 0 ) { - $md5 = base64_encode( md5( $body, true ) ); - return $request->withHeader( 'Content-MD5', $md5 ); - } - return $request; + // count md5 + private function addMd5( $request ) { + $body = $request->getBody(); + if ( $body && $body->getSize() > 0 ) { + $md5 = base64_encode( md5( $body, true ) ); + return $request->withHeader( 'Content-MD5', $md5 ); } + return $request; + } - // inventoryId + // inventoryId + public function specialParamTransformer( CommandInterface $command, $request ) { + $action = $command->getName(); + if ( $action == 'PutBucketInventory' ) { + $id = $command['Id']; + $uri = $request->getUri(); + $query = $uri->getQuery(); + $uri = $uri->withQuery( $query . '&Id='.$id ); + return $request->withUri( $uri ); + } + return $request; + } - public function specialParamTransformer( CommandInterface $command, $request ) { - $action = $command->getName(); - if ( $action == 'PutBucketInventory' ) { - $id = $command['Id']; + public function ciParamTransformer( CommandInterface $command, $request ) { + $action = $command->getName(); + if ( $action == 'GetObject' ) { + if(str_contains($uri = $request->getUri(), '%21') ) { + $uri = new Uri( str_replace('%21', '!', $uri) ); + $request = $request->withUri( $uri ); + } + if(isset($command['ImageHandleParam']) && $command['ImageHandleParam']){ $uri = $request->getUri(); $query = $uri->getQuery(); - $uri = $uri->withQuery( $query . '&Id='.$id ); - return $request->withUri( $uri ); - } - return $request; - } - - public function ciParamTransformer( CommandInterface $command, $request ) { - $action = $command->getName(); - if ( $action == 'GetObject' ) { - if(str_contains($uri = $request->getUri(), '%21') ) { - $uri = new Uri( str_replace('%21', '!', $uri) ); - $request = $request->withUri( $uri ); - } - if(isset($command['ImageHandleParam']) && $command['ImageHandleParam']){ - $uri = $request->getUri(); - $query = $uri->getQuery(); - if($query){ - $query .= "&" . urlencode($command['ImageHandleParam']); - }else{ - $query .= urlencode($command['ImageHandleParam']); - } - $uri = $uri->withQuery($query); - $request = $request->withUri( $uri ); + if($query){ + $query .= "&" . urlencode($command['ImageHandleParam']); + }else{ + $query .= urlencode($command['ImageHandleParam']); } + $uri = $uri->withQuery($query); + $request = $request->withUri( $uri ); } - return $request; } + return $request; + } - public function cosDomain2CiTransformer(CommandInterface $command, $request) { - $action = $command->getName(); - if(key_exists($action, array( - 'DescribeMediaBuckets' => 1, - 'DescribeDocProcessBuckets' => 1, - 'GetPicBucketList' => 1, - 'GetAiBucketList' => 1, - ))) { - $origin_host = "ci.{$this->config['region']}.myqcloud.com"; - $host = $origin_host; - if ($this->config['ip'] != null) { - $host = $this->config['ip']; - if ($this->config['port'] != null) { - $host = $this->config['ip'] . ':' . $this->config['port']; - } - } - - // 万象接口需要https,http方式报错 - if ($this->config['scheme'] !== 'https') { - $e = new Exception\CosException('CI request scheme must be "https", instead of "http"'); - $e->setExceptionCode('Invalid Argument'); - throw $e; + public function cosDomain2CiTransformer(CommandInterface $command, $request) { + $action = $command->getName(); + if(key_exists($action, array( + 'DescribeMediaBuckets' => 1, + 'DescribeDocProcessBuckets' => 1, + 'GetPicBucketList' => 1, + 'GetAiBucketList' => 1, + ))) { + $origin_host = "ci.{$this->config['region']}.myqcloud.com"; + $host = $origin_host; + if ($this->config['ip'] != null) { + $host = $this->config['ip']; + if ($this->config['port'] != null) { + $host = $this->config['ip'] . ':' . $this->config['port']; } - $path = $this->config['scheme'].'://'. $host . $request->getUri()->getPath(); - $uri = new Uri( $path ); - $query = $request->getUri()->getQuery(); - $uri = $uri->withQuery( $query ); - $request = $request->withUri( $uri ); - $request = $request->withHeader( 'Host', $origin_host ); - return $request; } - $ciActions = array( - 'DetectText' => 1, - 'CreateMediaTranscodeJobs' => 1, - 'CreateMediaJobs' => 1, - 'DescribeMediaJob' => 1, - 'DescribeMediaJobs' => 1, - 'CreateMediaSnapshotJobs' => 1, - 'CreateMediaConcatJobs' => 1, - 'DetectAudio' => 1, - 'GetDetectAudioResult' => 1, - 'GetDetectTextResult' => 1, - 'DetectVideo' => 1, - 'GetDetectVideoResult' => 1, - 'DetectDocument' => 1, - 'GetDetectDocumentResult' => 1, - 'CreateDocProcessJobs' => 1, - 'DescribeDocProcessQueues' => 1, - 'DescribeDocProcessJob' => 1, - 'GetDescribeDocProcessJobs' => 1, - 'DetectImages' => 1, - 'GetDetectImageResult' => 1, - 'DetectVirus' => 1, - 'GetDetectVirusResult' => 1, - 'CreateMediaVoiceSeparateJobs' => 1, - 'DescribeMediaVoiceSeparateJob' => 1, - 'DetectWebpage' => 1, - 'GetDetectWebpageResult' => 1, - 'DescribeMediaQueues' => 1, - 'UpdateMediaQueue' => 1, - 'CreateMediaSmartCoverJobs' => 1, - 'CreateMediaVideoProcessJobs' => 1, - 'CreateMediaVideoMontageJobs' => 1, - 'CreateMediaAnimationJobs' => 1, - 'CreateMediaPicProcessJobs' => 1, - 'CreateMediaSegmentJobs' => 1, - 'CreateMediaVideoTagJobs' => 1, - 'CreateMediaSuperResolutionJobs' => 1, - 'CreateMediaSDRtoHDRJobs' => 1, - 'CreateMediaDigitalWatermarkJobs' => 1, - 'CreateMediaExtractDigitalWatermarkJobs' => 1, - 'DetectLiveVideo' => 1, - 'CancelLiveVideoAuditing' => 1, - 'TriggerWorkflow' => 1, - 'GetWorkflowInstances' => 1, - 'GetWorkflowInstance' => 1, - 'CreateMediaSnapshotTemplate' => 1, - 'UpdateMediaSnapshotTemplate' => 1, - 'CreateMediaTranscodeTemplate' => 1, - 'UpdateMediaTranscodeTemplate' => 1, - 'CreateMediaHighSpeedHdTemplate' => 1, - 'UpdateMediaHighSpeedHdTemplate' => 1, - 'CreateMediaAnimationTemplate' => 1, - 'UpdateMediaAnimationTemplate' => 1, - 'CreateMediaConcatTemplate' => 1, - 'UpdateMediaConcatTemplate' => 1, - 'CreateMediaVideoProcessTemplate' => 1, - 'UpdateMediaVideoProcessTemplate' => 1, - 'CreateMediaVideoMontageTemplate' => 1, - 'UpdateMediaVideoMontageTemplate' => 1, - 'CreateMediaVoiceSeparateTemplate' => 1, - 'UpdateMediaVoiceSeparateTemplate' => 1, - 'CreateMediaSuperResolutionTemplate' => 1, - 'UpdateMediaSuperResolutionTemplate' => 1, - 'CreateMediaPicProcessTemplate' => 1, - 'UpdateMediaPicProcessTemplate' => 1, - 'CreateMediaWatermarkTemplate' => 1, - 'UpdateMediaWatermarkTemplate' => 1, - 'DescribeMediaTemplates' => 1, - 'DescribeWorkflow' => 1, - 'DeleteWorkflow' => 1, - 'CreateInventoryTriggerJob' => 1, - 'DescribeInventoryTriggerJobs' => 1, - 'DescribeInventoryTriggerJob' => 1, - 'CancelInventoryTriggerJob' => 1, - 'CreateMediaNoiseReductionJobs' => 1, - 'ImageSearchOpen' => 1, - 'UpdateDocProcessQueue' => 1, - 'CreateMediaQualityEstimateJobs' => 1, - 'CreateMediaStreamExtractJobs' => 1, - 'OpenFileProcessService' => 1, - 'GetFileProcessQueueList' => 1, - 'UpdateFileProcessQueue' => 1, - 'CreateFileHashCodeJobs' => 1, - 'GetFileHashCodeResult' => 1, - 'CreateFileUncompressJobs' => 1, - 'GetFileUncompressResult' => 1, - 'CreateFileCompressJobs' => 1, - 'GetFileCompressResult' => 1, - 'CreateM3U8PlayListJobs' => 1, - 'GetPicQueueList' => 1, - 'UpdatePicQueue' => 1, - 'OpenAiService' => 1, - 'CloseAiService' => 1, - 'GetAiQueueList' => 1, - 'UpdateAiQueue' => 1, - 'CreateMediaTranscodeProTemplate' => 1, - 'UpdateMediaTranscodeProTemplate' => 1, - 'CreateVoiceTtsTemplate' => 1, - 'UpdateVoiceTtsTemplate' => 1, - 'CreateMediaSmartCoverTemplate' => 1, - 'UpdateMediaSmartCoverTemplate' => 1, - 'CreateVoiceSpeechRecognitionTemplate' => 1, - 'UpdateVoiceSpeechRecognitionTemplate' => 1, - 'CreateVoiceTtsJobs' => 1, - 'CreateAiTranslationJobs' => 1, - 'CreateVoiceSpeechRecognitionJobs' => 1, - 'CreateAiWordsGeneralizeJobs' => 1, - 'CreateMediaVideoEnhanceJobs' => 1, - 'CreateMediaVideoEnhanceTemplate' => 1, - 'UpdateMediaVideoEnhanceTemplate' => 1, - 'CreateMediaTargetRecTemplate' => 1, - 'UpdateMediaTargetRecTemplate' => 1, - 'CreateMediaTargetRecJobs' => 1, - 'CreateMediaSegmentVideoBodyJobs' => 1, - ); - if (key_exists($action, $ciActions)) { - // 万象接口需要https,http方式报错 - if ($this->config['scheme'] !== 'https') { - $e = new Exception\CosException('CI request scheme must be "https", instead of "http"'); - $e->setExceptionCode('Invalid Argument'); - throw $e; - } - $bucketname = $command['Bucket']; - $appId = $this->config['appId']; - if ( $appId != null && endWith( $bucketname, '-'.$appId ) == false ) { - $bucketname = $bucketname.'-'.$appId; - } - $command['Bucket'] = $bucketname; - $domain_type = '.ci.'; - $origin_host = $bucketname . $domain_type . $this->config['region'] . '.' . $this->config['endpoint']; - $host = $origin_host; - if ( $this->config['ip'] != null ) { - $host = $this->config['ip']; - if ( $this->config['port'] != null ) { - $host = $this->config['ip'] . ':' . $this->config['port']; - } - } - $path = $this->config['scheme'].'://'. $host . $request->getUri()->getPath(); - $uri = new Uri( $path ); - $query = $request->getUri()->getQuery(); - $uri = $uri->withQuery( $query ); - $request = $request->withUri( $uri ); - $request = $request->withHeader( 'Host', $origin_host ); + // 万象接口需要https,http方式报错 + if ($this->config['scheme'] !== 'https') { + $e = new Exception\CosException('CI request scheme must be "https", instead of "http"'); + $e->setExceptionCode('Invalid Argument'); + throw $e; } + $path = $this->config['scheme'].'://'. $host . $request->getUri()->getPath(); + $uri = new Uri( $path ); + $query = $request->getUri()->getQuery(); + $uri = $uri->withQuery( $query ); + $request = $request->withUri( $uri ); + $request = $request->withHeader( 'Host', $origin_host ); return $request; } + $ciActions = array( + 'DetectText' => 1, + 'CreateMediaTranscodeJobs' => 1, + 'CreateMediaJobs' => 1, + 'DescribeMediaJob' => 1, + 'DescribeMediaJobs' => 1, + 'CreateMediaSnapshotJobs' => 1, + 'CreateMediaConcatJobs' => 1, + 'DetectAudio' => 1, + 'GetDetectAudioResult' => 1, + 'GetDetectTextResult' => 1, + 'DetectVideo' => 1, + 'GetDetectVideoResult' => 1, + 'DetectDocument' => 1, + 'GetDetectDocumentResult' => 1, + 'CreateDocProcessJobs' => 1, + 'DescribeDocProcessQueues' => 1, + 'DescribeDocProcessJob' => 1, + 'GetDescribeDocProcessJobs' => 1, + 'DetectImages' => 1, + 'GetDetectImageResult' => 1, + 'DetectVirus' => 1, + 'GetDetectVirusResult' => 1, + 'CreateMediaVoiceSeparateJobs' => 1, + 'DescribeMediaVoiceSeparateJob' => 1, + 'DetectWebpage' => 1, + 'GetDetectWebpageResult' => 1, + 'DescribeMediaQueues' => 1, + 'UpdateMediaQueue' => 1, + 'CreateMediaSmartCoverJobs' => 1, + 'CreateMediaVideoProcessJobs' => 1, + 'CreateMediaVideoMontageJobs' => 1, + 'CreateMediaAnimationJobs' => 1, + 'CreateMediaPicProcessJobs' => 1, + 'CreateMediaSegmentJobs' => 1, + 'CreateMediaVideoTagJobs' => 1, + 'CreateMediaSuperResolutionJobs' => 1, + 'CreateMediaSDRtoHDRJobs' => 1, + 'CreateMediaDigitalWatermarkJobs' => 1, + 'CreateMediaExtractDigitalWatermarkJobs' => 1, + 'DetectLiveVideo' => 1, + 'CancelLiveVideoAuditing' => 1, + 'TriggerWorkflow' => 1, + 'GetWorkflowInstances' => 1, + 'GetWorkflowInstance' => 1, + 'CreateMediaSnapshotTemplate' => 1, + 'UpdateMediaSnapshotTemplate' => 1, + 'CreateMediaTranscodeTemplate' => 1, + 'UpdateMediaTranscodeTemplate' => 1, + 'CreateMediaHighSpeedHdTemplate' => 1, + 'UpdateMediaHighSpeedHdTemplate' => 1, + 'CreateMediaAnimationTemplate' => 1, + 'UpdateMediaAnimationTemplate' => 1, + 'CreateMediaConcatTemplate' => 1, + 'UpdateMediaConcatTemplate' => 1, + 'CreateMediaVideoProcessTemplate' => 1, + 'UpdateMediaVideoProcessTemplate' => 1, + 'CreateMediaVideoMontageTemplate' => 1, + 'UpdateMediaVideoMontageTemplate' => 1, + 'CreateMediaVoiceSeparateTemplate' => 1, + 'UpdateMediaVoiceSeparateTemplate' => 1, + 'CreateMediaSuperResolutionTemplate' => 1, + 'UpdateMediaSuperResolutionTemplate' => 1, + 'CreateMediaPicProcessTemplate' => 1, + 'UpdateMediaPicProcessTemplate' => 1, + 'CreateMediaWatermarkTemplate' => 1, + 'UpdateMediaWatermarkTemplate' => 1, + 'DescribeMediaTemplates' => 1, + 'DescribeWorkflow' => 1, + 'DeleteWorkflow' => 1, + 'CreateInventoryTriggerJob' => 1, + 'DescribeInventoryTriggerJobs' => 1, + 'DescribeInventoryTriggerJob' => 1, + 'CancelInventoryTriggerJob' => 1, + 'CreateMediaNoiseReductionJobs' => 1, + 'ImageSearchOpen' => 1, + 'UpdateDocProcessQueue' => 1, + 'CreateMediaQualityEstimateJobs' => 1, + 'CreateMediaStreamExtractJobs' => 1, + 'OpenFileProcessService' => 1, + 'GetFileProcessQueueList' => 1, + 'UpdateFileProcessQueue' => 1, + 'CreateFileHashCodeJobs' => 1, + 'GetFileHashCodeResult' => 1, + 'CreateFileUncompressJobs' => 1, + 'GetFileUncompressResult' => 1, + 'CreateFileCompressJobs' => 1, + 'GetFileCompressResult' => 1, + 'CreateM3U8PlayListJobs' => 1, + 'GetPicQueueList' => 1, + 'UpdatePicQueue' => 1, + 'OpenAiService' => 1, + 'CloseAiService' => 1, + 'GetAiQueueList' => 1, + 'UpdateAiQueue' => 1, + 'CreateMediaTranscodeProTemplate' => 1, + 'UpdateMediaTranscodeProTemplate' => 1, + 'CreateVoiceTtsTemplate' => 1, + 'UpdateVoiceTtsTemplate' => 1, + 'CreateMediaSmartCoverTemplate' => 1, + 'UpdateMediaSmartCoverTemplate' => 1, + 'CreateVoiceSpeechRecognitionTemplate' => 1, + 'UpdateVoiceSpeechRecognitionTemplate' => 1, + 'CreateVoiceTtsJobs' => 1, + 'CreateAiTranslationJobs' => 1, + 'CreateVoiceSpeechRecognitionJobs' => 1, + 'CreateAiWordsGeneralizeJobs' => 1, + 'CreateMediaVideoEnhanceJobs' => 1, + 'CreateMediaVideoEnhanceTemplate' => 1, + 'UpdateMediaVideoEnhanceTemplate' => 1, + 'CreateMediaTargetRecTemplate' => 1, + 'UpdateMediaTargetRecTemplate' => 1, + 'CreateMediaTargetRecJobs' => 1, + 'CreateMediaSegmentVideoBodyJobs' => 1, + ); + if (key_exists($action, $ciActions)) { + // 万象接口需要https,http方式报错 + if ($this->config['scheme'] !== 'https') { + $e = new Exception\CosException('CI request scheme must be "https", instead of "http"'); + $e->setExceptionCode('Invalid Argument'); + throw $e; + } - public function __destruct() { + $bucketname = $command['Bucket']; + $appId = $this->config['appId']; + if ( $appId != null && endWith( $bucketname, '-'.$appId ) == false ) { + $bucketname = $bucketname.'-'.$appId; + } + $command['Bucket'] = $bucketname; + $domain_type = '.ci.'; + $origin_host = $bucketname . $domain_type . $this->config['region'] . '.' . $this->config['endpoint']; + $host = $origin_host; + if ( $this->config['ip'] != null ) { + $host = $this->config['ip']; + if ( $this->config['port'] != null ) { + $host = $this->config['ip'] . ':' . $this->config['port']; + } + } + $path = $this->config['scheme'].'://'. $host . $request->getUri()->getPath(); + $uri = new Uri( $path ); + $query = $request->getUri()->getQuery(); + $uri = $uri->withQuery( $query ); + $request = $request->withUri( $uri ); + $request = $request->withHeader( 'Host', $origin_host ); } + return $request; + } + public function __destruct() { } +} diff --git a/src/Copy.php b/src/Copy.php index 18b3d035..23c887ce 100644 --- a/src/Copy.php +++ b/src/Copy.php @@ -18,6 +18,8 @@ class Copy { private $size; private $commandList = []; private $requestList = []; + private $concurrency; + private $retry; public function __construct($client, $source, $options = array()) { $minPartSize = $options['PartSize']; @@ -108,7 +110,7 @@ public function uploadParts($uploadId) { $this->parts[$index] = $part; } catch(\Exception $e) { if ($i == $retry) { - throw($e); + throw $e; } } } @@ -136,5 +138,4 @@ private function initiateMultipartUpload() { $result = $this->client->createMultipartUpload($this->options); return $result['UploadId']; } - } diff --git a/src/ExceptionMiddleware.php b/src/ExceptionMiddleware.php index 3bc980af..f2066b85 100644 --- a/src/ExceptionMiddleware.php +++ b/src/ExceptionMiddleware.php @@ -6,7 +6,6 @@ use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use GuzzleHttp\Exception\RequestException; class ExceptionMiddleware { private $nextHandler; @@ -43,7 +42,6 @@ public function handle(RequestInterface $request, ResponseInterface $response) { return $response; } - //throw RequestException::create($request, $response); $parts = $this->parser->parse($request, $response); $className = 'Qcloud\\Cos\\Exception\\' . $parts['code']; diff --git a/src/MultipartUpload.php b/src/MultipartUpload.php index 2eec9c0c..9967efa0 100644 --- a/src/MultipartUpload.php +++ b/src/MultipartUpload.php @@ -18,6 +18,10 @@ class MultipartUpload { private $progress; private $totalSize; private $uploadedSize; + private $concurrency; + private $partNumberList; + private $needMd5; + private $retry; public function __construct($client, $body, $options = array()) { $minPartSize = $options['PartSize']; @@ -35,6 +39,7 @@ public function __construct($client, $body, $options = array()) { $this->needMd5 = isset($options['ContentMD5']) ? $options['ContentMD5'] : true; $this->retry = isset($options['Retry']) ? $options['Retry'] : 3; } + public function performUploading() { $uploadId= $this->initiateMultipartUpload(); $this->uploadParts($uploadId); @@ -51,6 +56,7 @@ public function performUploading() { ); } + public function uploadParts($uploadId) { $uploadRequests = function ($uploadId) { $partNumber = 1; @@ -163,5 +169,4 @@ private function initiateMultipartUpload() { $result = $this->client->createMultipartUpload($this->options); return $result['UploadId']; } - } diff --git a/src/RangeDownload.php b/src/RangeDownload.php index 77f50f7c..425a63f7 100644 --- a/src/RangeDownload.php +++ b/src/RangeDownload.php @@ -14,21 +14,27 @@ class RangeDownload { private $progress; private $totalSize; private $resumableJson; + private $concurrency; + private $partNumberList; + private $downloadedSize; + private $saveAs; + private $resumableTaskFile; + private $resumableDownload; + private $resumableJsonLocal; + private $fp; + private $fp_resume; public function __construct( $client, $contentLength, $saveAs, $options = array() ) { $this->client = $client; $this->options = $options; $this->partSize = isset( $options['PartSize'] ) ? $options['PartSize'] : self::DEFAULT_PART_SIZE; $this->concurrency = isset( $options['Concurrency'] ) ? $options['Concurrency'] : 10; - $this->progress = isset( $options['Progress'] ) ? $options['Progress'] : function( $totalSize, $downloadedSize ) { - } - ; + $this->progress = isset( $options['Progress'] ) ? $options['Progress'] : function( $totalSize, $downloadedSize ) {}; $this->parts = []; $this->partNumberList = []; $this->downloadedSize = 0; $this->totalSize = $contentLength; $this->saveAs = $saveAs; - $this->resumableJson = []; $this->resumableJson = isset( $options['ResumableJson'] ) ? $options['ResumableJson'] : []; unset( $options['ResumableJson'] ); $this->resumableTaskFile = isset( $options['ResumableTaskFile'] ) ? $options['ResumableTaskFile'] : $saveAs . '.cosresumabletask'; @@ -141,5 +147,4 @@ public function donwloadParts() { $promise = $pool->promise(); $promise->wait(); } - }