| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\FileSystem\Drivers; |
| 4 |
|
| 5 |
use FluentCart\App\Modules\StorageDrivers\BaseStorageDriver; |
| 6 |
|
| 7 |
abstract class BaseDriver |
| 8 |
{ |
| 9 |
protected ?string $dirPath; |
| 10 |
protected ?string $dirName; |
| 11 |
|
| 12 |
protected ?BaseStorageDriver $storageDriver; |
| 13 |
|
| 14 |
public function __construct(?string $dirPath = null, ?string $dirName = null) |
| 15 |
{ |
| 16 |
$this->dirName = $dirName; |
| 17 |
$this->dirPath = $dirPath; |
| 18 |
} |
| 19 |
|
| 20 |
public function getStorageDriver(): ?BaseStorageDriver |
| 21 |
{ |
| 22 |
return $this->storageDriver; |
| 23 |
} |
| 24 |
|
| 25 |
public function saveSettings($params) |
| 26 |
{ |
| 27 |
return $this->storageDriver->saveSettings($params); |
| 28 |
} |
| 29 |
|
| 30 |
public function buckets() |
| 31 |
{ |
| 32 |
return []; |
| 33 |
} |
| 34 |
|
| 35 |
protected abstract function getDefaultDirPath(); |
| 36 |
|
| 37 |
public abstract function listFiles(array $params = []); |
| 38 |
|
| 39 |
public abstract function uploadFile($localFilePath, $uploadToFilePath, $file, $params = []); |
| 40 |
|
| 41 |
|
| 42 |
public abstract function downloadFile(string $filePath); |
| 43 |
|
| 44 |
public abstract function getSignedDownloadUrl(string $filePath, $bucket = null, $productDownload = null); |
| 45 |
|
| 46 |
public abstract function getFilePath(string $filePath); |
| 47 |
|
| 48 |
protected abstract function retrieveFileForDownload(string $downloadableFilePath); |
| 49 |
|
| 50 |
public function setDownloadHeader($fileName, $file, $fileSize = null) |
| 51 |
{ |
| 52 |
$extension = pathinfo($file, PATHINFO_EXTENSION); |
| 53 |
// Append extension if $fileName doesn't already have one |
| 54 |
if (pathinfo($fileName, PATHINFO_EXTENSION) === '') { |
| 55 |
$fileName .= '.' . $extension; |
| 56 |
} |
| 57 |
|
| 58 |
header('Content-Description: File Transfer'); |
| 59 |
header('Content-Type: application/octet-stream', true, 200); |
| 60 |
header('Content-Disposition: attachment; filename="' . $fileName . '"'); |
| 61 |
if (!empty($fileSize)) { |
| 62 |
header('Content-Length: ' . $fileSize); |
| 63 |
//header('Content-Length: ' . filesize($file)); |
| 64 |
} |
| 65 |
|
| 66 |
header('Expires: 0'); |
| 67 |
header('Cache-Control: must-revalidate'); |
| 68 |
header('Pragma: public'); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
} |