88 */
99
1010use BulkGate \Plugin \{Settings \Repository \Entity \Setting , Strict , Structure \Collection };
11- use function array_key_exists , array_merge ;
11+ use function array_key_exists , array_merge , preg_match ;
1212
1313class Settings
1414{
@@ -19,6 +19,11 @@ class Settings
1919 */
2020 private array $ settings = [];
2121
22+ /**
23+ * @var array<string, mixed>
24+ */
25+ private array $ default_settings = [];
26+
2227 private Repository \Settings $ repository ;
2328
2429 public function __construct (Repository \Settings $ repository )
@@ -27,6 +32,21 @@ public function __construct(Repository\Settings $repository)
2732 }
2833
2934
35+ /**
36+ * @param array<array-key, mixed> $settings
37+ */
38+ public function setDefaultSettings (array $ settings ): void
39+ {
40+ $ this ->default_settings = [];
41+
42+ foreach ($ settings as $ key => $ value ) if (is_string ($ key ) && preg_match ('~^[\w_-]+?:?[\w_-]+?$~U ' , $ key ))
43+ {
44+ $ this ->default_settings [$ key ] = $ value ;
45+ }
46+ }
47+
48+
49+
3050 /**
3151 * @return mixed
3252 */
@@ -45,7 +65,7 @@ public function load(string $settings_key, bool $reload = false)
4565 {
4666 return ($ this ->settings [$ scope ][$ key ]->value );
4767 }
48- return null ;
68+ return $ this -> default_settings [ $ settings_key ] ?? null ;
4969 }
5070 return $ this ->settings [$ scope ]->toArray ();
5171 }
0 commit comments