Skip to content

Commit

Permalink
optionally can define endpoint URL
Browse files Browse the repository at this point in the history
  • Loading branch information
schneidermr committed Nov 18, 2023
1 parent 983e6de commit 5af2bd0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class S3 extends Device
* @param string $region
* @param string $acl
*/
public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_EAST_1, string $acl = self::ACL_PRIVATE)
public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_EAST_1, string $acl = self::ACL_PRIVATE, $endpointUrl = '')
{
$this->accessKey = $accessKey;
$this->secretKey = $secretKey;
Expand All @@ -158,10 +158,14 @@ public function __construct(string $root, string $accessKey, string $secretKey,
$this->acl = $acl;
$this->amzHeaders = [];

$host = match ($region) {
self::CN_NORTH_1, self::CN_NORTH_4, self::CN_NORTHWEST_1 => $bucket.'.s3.'.$region.'.amazonaws.cn',
default => $bucket.'.s3.'.$region.'.amazonaws.com'
};
if (!empty($endpointUrl)) {
$host = $bucket.'.'.$endpointUrl;
} else {
$host = match ($region) {
self::CN_NORTH_1, self::CN_NORTH_4, self::CN_NORTHWEST_1 => $bucket.'.s3.'.$region.'.amazonaws.cn',
default => $bucket.'.s3.'.$region.'.amazonaws.com'
};
}

$this->headers['host'] = $host;
}
Expand Down

0 comments on commit 5af2bd0

Please sign in to comment.