Skip to content

Commit 3ca7682

Browse files
authored
feature endpoint (#98)
1 parent ca816d6 commit 3ca7682

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Qcloud/Cos/BucketStyleListener.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ class BucketStyleListener implements EventSubscriberInterface {
2222
private $ip;
2323
private $port;
2424
private $ipport;
25+
private $endpoint;
2526

26-
public function __construct($appId, $ip=null, $port=null) {
27+
public function __construct($appId, $ip=null, $port=null, $endpoint=null) {
2728
$this->appId = $appId;
2829
$this->ip = $ip;
2930
$this->port = $port;
3031
$this->ipport = null;
32+
$this->endpoint = $endpoint;
3133
if ($ip != null) {
3234
$this->ipport = $ip;
3335
if ($port != null) {
@@ -81,7 +83,12 @@ public function onCommandAfterPrepare(Event $event) {
8183
$request->setHost($this->ipport);
8284
$request->setHeader('Host', $realHost);
8385
} else {
84-
$request->setHost($realHost);
86+
if($this->endpoint != null) {
87+
$tmp = $bucket. '.' . $this->endpoint;
88+
$request->setHost($tmp);
89+
} else {
90+
$request->setHost($realHost);
91+
}
8592
}
8693
if (!$bucket) {
8794
$request->getParams()->set('cos.resource', '/');
@@ -93,4 +100,4 @@ public function onCommandAfterPrepare(Event $event) {
93100
);
94101
}
95102
}
96-
}
103+
}

src/Qcloud/Cos/Client.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Client extends GSClient {
2525
private $schema;
2626
private $ip;
2727
private $port;
28-
29-
3028
public function __construct($config) {
3129
$this->region = $config['region'];
3230
$regionmap = array('cn-east'=>'ap-shanghai',
@@ -44,6 +42,7 @@ public function __construct($config) {
4442
$this->schema = isset($config['schema']) ? $config['schema'] : 'http';
4543
$this->ip = isset($config['ip']) ? $config['ip'] : null;
4644
$this->port = isset($config['port']) ? $config['port'] : null;
45+
$this->endpoint = isset($config['endpoint']) ? $config['endpoint'] : null;
4746
$this->region = isset($regionmap[$this->region]) ? $regionmap[$this->region] : $this->region;
4847
$this->credentials = $config['credentials'];
4948
$this->appId = isset($config['credentials']['appId']) ? $config['credentials']['appId'] : null;
@@ -64,7 +63,7 @@ public function __construct($config) {
6463
$this->addSubscriber(new Md5Listener($this->signature));
6564
$this->addSubscriber(new TokenListener($this->token));
6665
$this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey));
67-
$this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port));
66+
$this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port, $this->endpoint));
6867
// Allow for specifying bodies with file paths and file handles
6968
$this->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart')));
7069
}

0 commit comments

Comments
 (0)