| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace common\components\uploaddrive;
- use common\helpers\RegularHelper;
- use common\models\common\Attachment;
- use League\Flysystem\Filesystem;
- use Overtrue\Flysystem\Cos\CosAdapter;
- use Overtrue\Flysystem\Qiniu\QiniuAdapter;
- use Xxtime\Flysystem\Aliyun\OssAdapter;
- /**
- * Interface DriveInterface
- * @package common\components\uploaddrive
- */
- abstract class DriveInterface
- {
- /**
- * @var array
- */
- protected $config;
- /**
- * @var CosAdapter|OssAdapter|QiniuAdapter
- */
- protected $adapter;
- /**
- * 上传组件
- *
- * @var Filesystem
- */
- protected $filesystem;
- /**
- * DriveInterface constructor.
- * @param $config
- */
- public function __construct($config)
- {
- $this->config = $config;
- $this->create();
- }
- /**
- * @return Filesystem
- */
- public function entity(): Filesystem
- {
- if (!$this->filesystem instanceof Filesystem) {
- $this->filesystem = new Filesystem($this->adapter);
- }
- return $this->filesystem;
- }
- /**
- * @param $baseInfo
- * @param $drive
- * @param $fullPath
- * @return mixed
- */
- public function getUrl($baseInfo, $drive, $fullPath)
- {
- $baseInfo = $this->baseUrl($baseInfo, $fullPath);
- if ($drive != Attachment::DRIVE_LOCAL && !RegularHelper::verify('url', $baseInfo['url'])) {
- $baseInfo['url'] = 'http://' . $baseInfo['url'];
- }
- return $baseInfo;
- }
- /**
- * @param $baseInfo
- * @param $drive
- * @param $fullPath
- * @return mixed
- */
- public function getDomainName($baseInfo, $drive, $fullPath)
- {
- $baseInfo = $this->domainName($baseInfo, $fullPath);
- if ($drive != Attachment::DRIVE_LOCAL && !RegularHelper::verify('url', $baseInfo['domain_name'])) {
- $baseInfo['domain_name'] = 'http://' . $baseInfo['domain_name'];
- }
- return $baseInfo;
- }
- /**
- * 返回路由
- *
- * @param $baseInfo
- * @param $fullPath
- * @return $baseInfo
- */
- abstract protected function baseUrl($baseInfo, $fullPath);
- /**
- * 返回域名
- *
- * @param $baseInfo
- * @param $fullPath
- * @return $baseInfo
- */
- abstract protected function domainName($baseInfo, $fullPath);
- /**
- * @return mixed
- */
- abstract protected function create();
- }
|