diff --git a/README.md b/README.md index b6ce233..f19e4aa 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,22 @@ $ composer require overtrue/flysystem-cos -vvv use League\Flysystem\Filesystem; use Overtrue\Flysystem\Cos\CosAdapter; -$secretId = 'AKIDsiQzQla780mQxLLU2GJC6xxxxxxxxxx'; -$secretKey = 'b0GMH2c2NXWKxPhy7xxxxxxxxxxxx'; -$region = 'ap-guangzhou'; -$bucket = 'overtrue-123456789'; - -$adapter = new CosAdapter($secretId, $secretKey, $bucket, $region); +$config = [ + 'region' => 'ap-guangzhou', + 'credentials' => [ + 'appId' => 1234567889, // 域名中数字部分 + 'secretId' => 'AKIDS5jNr5NNygGxxxxxxxxxxxxxxxxxx', + 'secretKey' => 'NfszEWmyDqGmao0a4XS8wxxxxxxxxxxxx', + ], + 'bucket' => 'test', + 'timeout' => 60, + 'connect_timeout' => 60, + 'cdn' => '您的 CDN 域名', + 'scheme' => 'https', + 'read_from_cdn' => false, +]; + +$adapter = new CosAdapter($config); $flysystem = new League\Flysystem\Filesystem($adapter); diff --git a/src/CosAdapter.php b/src/CosAdapter.php index 72bd5da..7cd915e 100644 --- a/src/CosAdapter.php +++ b/src/CosAdapter.php @@ -40,18 +40,11 @@ class CosAdapter extends AbstractAdapter implements CanOverwriteFiles /** * CosAdapter constructor. * - * @param string $secretId - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param array $optional - */ - public function __construct($secretId, $secretKey, $bucket, $region, array $optional = []) - { - $this->config = array_merge( - \compact('region', 'bucket'), [ - 'credentials' => \compact('secretId', 'secretKey'), - ], $optional); + * @param array $config + */ + public function __construct(array $config = []) + { + $this->config = $config; $this->setPathPrefix($this->config['cdn'] ?? ''); }