PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.20
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.20
1.6.6 1.6.5 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 All 49 releases
fluent-cart / app / Modules / StorageDrivers / S3 / S3Settings.php

S3Settings.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.20, at app/Modules/StorageDrivers/S3/S3Settings.php

81 lines 1.9 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\Modules\StorageDrivers\S3;
4
5 use FluentCart\Framework\Support\Arr;
6
7 class S3Settings
8 {
9
10 protected $settings;
11
12 protected $driverHandler = 'fluent_cart_storage_settings_s3';
13
14 static ?array $cachedSettings = null;
15
16 public bool $isUsingDefineMode = false;
17
18 public function __construct()
19 {
20 if (self::$cachedSettings) {
21 $this->settings = self::$cachedSettings;
22 return;
23 }
24 $settings = fluent_cart_get_option($this->driverHandler, []);
25
26 $this->isUsingDefineMode = defined('FCT_S3_ACCESS_KEY') && defined('FCT_S3_SECRET_KEY');
27
28 $this->settings = wp_parse_args($settings, static::getDefaults());
29
30 if ($this->isUsingDefineMode) {
31 $this->settings['is_using_define_mode'] = true;
32 $this->settings['access_key'] = FCT_S3_ACCESS_KEY;
33 $this->settings['secret_key'] = FCT_S3_SECRET_KEY;
34 }
35
36 $settings['region'] = 'us-east-1';
37 self::$cachedSettings = $this->settings;
38 }
39
40 public static function getDefaults()
41 {
42 return [
43 'is_active' => 'no',
44 'secret_key' => '',
45 'access_key' => '',
46 'bucket' => '',
47 'region' => 'us-east-1',
48 ];
49 }
50
51 public function isActive()
52 {
53 $settings = $this->get();
54
55 $isActive = Arr::get($settings, 'is_active') === 'yes';
56
57 if ($isActive) {
58 $requiredKeys = ['secret_key', 'access_key', 'region'];
59
60 return $this->hasRequiredKeys($settings, $requiredKeys);
61 }
62
63 return false;
64 }
65
66 private function hasRequiredKeys(array $settings, array $requiredKeys): bool
67 {
68 foreach ($requiredKeys as $key) {
69 if (empty(Arr::get($settings, $key))) {
70 return false;
71 }
72 }
73
74 return true;
75 }
76
77 public function get($key = '')
78 {
79 return $this->settings;
80 }
81 }