init
This commit is contained in:
84
code/extend/storage/StorageCore.php
Normal file
84
code/extend/storage/StorageCore.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace storage;
|
||||
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\AwsS3v3\AwsS3Adapter;
|
||||
use Aws\S3\S3Client;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
|
||||
class StorageCore
|
||||
{
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $Filesystem;
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var Local
|
||||
*/
|
||||
private $Adapter;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$arrConfig = config('storage');
|
||||
|
||||
$this->Adapter = new Local(
|
||||
$arrConfig['local']['dir']
|
||||
);
|
||||
|
||||
$this->Filesystem = new Filesystem($this->Adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function set($strKey, $strContent)
|
||||
{
|
||||
$strContent = zstd_compress($strContent);
|
||||
return $this->Filesystem->write($strKey, $strContent);
|
||||
}
|
||||
|
||||
|
||||
public function write($strKey, $strContent, array $arrConfig = [])
|
||||
{
|
||||
$strContent = zstd_compress($strContent);
|
||||
return $this->Filesystem->write($strKey, $strContent, $arrConfig);
|
||||
}
|
||||
|
||||
public function update($strKey, $strContent, array $arrConfig = [])
|
||||
{
|
||||
$strContent = zstd_compress($strContent);
|
||||
return $this->Filesystem->update($strKey, $strContent, $arrConfig);
|
||||
}
|
||||
|
||||
public function read($strKey)
|
||||
{
|
||||
$Stream = $this->Filesystem->readStream($strKey);
|
||||
$strContent = stream_get_contents($Stream);
|
||||
$strContent = zstd_uncompress($strContent);
|
||||
return $strContent;
|
||||
}
|
||||
|
||||
public function has($strKey)
|
||||
{
|
||||
return $this->Filesystem->has($strKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user