From 028df49026457c638f5e43867fc2c3141328de7c Mon Sep 17 00:00:00 2001 From: lewzylu Date: Tue, 5 Mar 2019 09:37:11 +0800 Subject: [PATCH] feature endpoint --- src/Qcloud/Cos/BucketStyleListener.php | 13 ++++++++++--- src/Qcloud/Cos/Client.php | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index a91d1ec0..c1c0fd1e 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -22,12 +22,14 @@ class BucketStyleListener implements EventSubscriberInterface { private $ip; private $port; private $ipport; + private $endpoint; - public function __construct($appId, $ip=null, $port=null) { + public function __construct($appId, $ip=null, $port=null, $endpoint=null) { $this->appId = $appId; $this->ip = $ip; $this->port = $port; $this->ipport = null; + $this->endpoint = $endpoint; if ($ip != null) { $this->ipport = $ip; if ($port != null) { @@ -81,7 +83,12 @@ public function onCommandAfterPrepare(Event $event) { $request->setHost($this->ipport); $request->setHeader('Host', $realHost); } else { - $request->setHost($realHost); + if($this->endpoint != null) { + $tmp = $bucket. '.' . $this->endpoint; + $request->setHost($tmp); + } else { + $request->setHost($realHost); + } } if (!$bucket) { $request->getParams()->set('cos.resource', '/'); @@ -93,4 +100,4 @@ public function onCommandAfterPrepare(Event $event) { ); } } -} +} diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index a58c3861..a397a192 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -25,8 +25,6 @@ class Client extends GSClient { private $schema; private $ip; private $port; - - public function __construct($config) { $this->region = $config['region']; $regionmap = array('cn-east'=>'ap-shanghai', @@ -44,6 +42,7 @@ public function __construct($config) { $this->schema = isset($config['schema']) ? $config['schema'] : 'http'; $this->ip = isset($config['ip']) ? $config['ip'] : null; $this->port = isset($config['port']) ? $config['port'] : null; + $this->endpoint = isset($config['endpoint']) ? $config['endpoint'] : null; $this->region = isset($regionmap[$this->region]) ? $regionmap[$this->region] : $this->region; $this->credentials = $config['credentials']; $this->appId = isset($config['credentials']['appId']) ? $config['credentials']['appId'] : null; @@ -64,7 +63,7 @@ public function __construct($config) { $this->addSubscriber(new Md5Listener($this->signature)); $this->addSubscriber(new TokenListener($this->token)); $this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey)); - $this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port)); + $this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port, $this->endpoint)); // Allow for specifying bodies with file paths and file handles $this->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart'))); }