PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / FileSystem / FileManager.php

FileManager.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/FileSystem/FileManager.php

104 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\FileSystem;
4
5 use FluentCart\Api\StorageDrivers;
6 use FluentCart\App\Services\FileSystem\Drivers\BaseDriver;
7 use FluentCart\App\Services\FileSystem\Drivers\Local\LocalDriver;
8 use FluentCart\App\Services\FileSystem\Drivers\S3\S3Driver;
9 use FluentCart\Framework\Support\Arr;
10
11 class FileManager
12 {
13 /**
14 * @var BaseDriver|S3Driver|LocalDriver $driver
15 **/
16 private $driver;
17 protected ?string $dirPath;
18 protected ?string $dirName;
19
20
21 public function getDriver()
22 {
23 return $this->driver;
24 }
25
26 public function __construct(
27 string $driver = 'local',
28 ?string $dirPath = null,
29 ?string $dirName = null,
30 $inActiveMode = false
31 )
32 {
33 $this->dirName = $dirName;
34 $this->dirPath = $dirPath;
35 $this->driver = $this->resolveDriver($driver, $inActiveMode);
36 }
37
38 public function listFiles(array $params = [])
39 {
40 return $this->driver->listFiles($params);
41 }
42
43 public function bucketLists()
44 {
45 return $this->driver->buckets();
46 }
47
48
49 public function uploadFile(string $localFilePath, string $uploadToFilePath, $file, array $params = [])
50 {
51 return $this->driver->uploadFile($localFilePath, $uploadToFilePath, $file, $params);
52 }
53
54 public function downloadFile(string $filePath, string $fileName, $bucket = null)
55 {
56 return $this->driver->downloadFile($filePath, $fileName, $bucket);
57 }
58
59 public function getSignedDownloadUrl(string $filePath, $bucket = null, $productDownload = null): ?string
60 {
61 return $this->driver->getSignedDownloadUrl($filePath, $bucket, $productDownload);
62 }
63
64 public function getFilePath(string $filePath, $bucket = null)
65 {
66 return $this->driver->getFilePath($filePath, null, $bucket);
67 }
68
69 public function deleteFile(string $filePath, $bucket = null)
70 {
71 return $this->driver->deleteFile($filePath, $bucket);
72 }
73
74
75 private function resolveDriver(string $driver, $inActiveMode)
76 {
77
78 $storageDrivers = new StorageDrivers();
79
80 if($inActiveMode){
81 $storages = $storageDrivers->getAll();
82 }else{
83 $storages = $storageDrivers->getActive(true);
84 }
85
86 $storage = Arr::get($storages, $driver.'.instance');
87
88 if(empty($storage)){
89 throw new \Exception(esc_html__('Invalid driver', 'fluent-cart'));
90 }
91
92 $driverClass = $storage->getDriverClass();
93
94 return new $driverClass($this->dirPath, $this->dirName);
95 }
96
97
98 public function saveSettings($params)
99 {
100 return $this->driver->saveSettings($params);
101 }
102
103 }
104