You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
949 B
PHTML

2 years ago
<?php
namespace Base\Tool;
use Exception;
class Storage {
/**
* @var StorageClient
*/
private static $client;
private static function getClient(): StorageClient {
if (empty(self::$client)) {
if (C('STORAGE_TYPE') == 'oss') {
self::$client = new OssClient();
} elseif (C('STORAGE_TYPE') == 'obs') {
self::$client = new ObsClient();
} else {
throw new Exception("Storage type undefined!");
}
}
return self::$client;
}
public static function upload($localFilePath, $saveFileName) {
return self::getClient()->upload($localFilePath, $saveFileName);
}
public static function delete($deleteFile)
{
return self::getClient()->delete($deleteFile);
}
public static function getUrl($saveFileName)
{
return self::getClient()->getUrl($saveFileName);
}
}