| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Api; |
| 4 |
|
| 5 |
use FluentCart\App\Services\FileSystem\Drivers\S3\S3FileList; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class StorageDrivers |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @param string $driver name like local, s3 etc |
| 12 |
* Get storage driver settings |
| 13 |
* @return array |
| 14 |
* |
| 15 |
*/ |
| 16 |
public function getSettings($driver) |
| 17 |
{ |
| 18 |
return apply_filters('fluent_cart/storage/get_global_storage_settings_' . $driver, [], []); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* @return array |
| 23 |
* |
| 24 |
* All storage drivers |
| 25 |
*/ |
| 26 |
public function getAll() |
| 27 |
{ |
| 28 |
return apply_filters('fluent_cart/storage/get_global_storage_drivers', [], []); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* @return array |
| 33 |
* |
| 34 |
* All active storage drivers |
| 35 |
*/ |
| 36 |
public function getActive($withInstance = false) |
| 37 |
{ |
| 38 |
$drivers = $this->getAll(); |
| 39 |
$activeDrivers = []; |
| 40 |
|
| 41 |
foreach ($drivers as $index => $driver) { |
| 42 |
$settings = $this->getSettings($driver['route']); |
| 43 |
$instance = $driver['instance']; |
| 44 |
|
| 45 |
|
| 46 |
if ($instance->isEnabled()) { |
| 47 |
if(!$withInstance){ |
| 48 |
unset($driver['instance']); |
| 49 |
} |
| 50 |
$activeDrivers[$index] = $driver; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
return $activeDrivers; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @param string $driver name like local, s3 etc |
| 59 |
* Get storage driver Status |
| 60 |
* @return array |
| 61 |
* |
| 62 |
*/ |
| 63 |
public function getStatus($driver) |
| 64 |
{ |
| 65 |
return apply_filters('fluent_cart/storage/get_global_storage_driver_status_' . $driver, [], []); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* @param array $data containing connect info and driver name like s3 etc |
| 70 |
* Get Verify connect info |
| 71 |
* @return array |
| 72 |
* |
| 73 |
*/ |
| 74 |
public function verifyConnectInfo(array $data) |
| 75 |
{ |
| 76 |
$driver = Arr::get($data, 'driver'); |
| 77 |
$settings = Arr::get($data, 'settings'); |
| 78 |
|
| 79 |
return apply_filters('fluent_cart/verify_driver_connect_info_' . sanitize_text_field($driver), $settings, []); |
| 80 |
} |
| 81 |
} |
| 82 |
|