`<?php
/**
- @desc 阿里云OSS适配器
- @author Tinywan(ShaoBo Wan)
- @Date 2022/3/7 19:54
*/
declare(strict_types=1);
namespace Tinywan\Storage\Adapter;
use OSS\Core\OssException;
use OSS\OssClient;
use Throwable;
use Tinywan\Storage\Exception\StorageException;
use OSS\Credentials\StaticCredentialsProvider;
class OssAdapter extends AdapterAbstract
{
protected $instance = null;
/**
* @desc: 阿里雲实例
*
* @throws OssException
*/
public function getInstance(): ?OssClient
{
if (is_null($this->instance)) {
$provider = new StaticCredentialsProvider($this->config['accessKeyId'], $this->config['accessKeySecret'], null);
$this->instance = new OssClient([
'provider' => $provider,
'endpoint'=>$this->config['endpoint'],
'cname' => $this->config['cname'],
'signatureVersion' => $this->config['signatureVersion'],
'region' => $this->config['region'],
]);
$this->instance->setUseSSL(true);
}
return $this->instance;
}
}`
`<?php
/**
*/
declare(strict_types=1);
namespace Tinywan\Storage\Adapter;
use OSS\Core\OssException;
use OSS\OssClient;
use Throwable;
use Tinywan\Storage\Exception\StorageException;
use OSS\Credentials\StaticCredentialsProvider;
class OssAdapter extends AdapterAbstract
{
protected $instance = null;
}`