Skip to content

Commit 2b0708d

Browse files
committed
feat: Various features and tweaks
1 parent 2d76792 commit 2b0708d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/Core/Config.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class XWC_Config implements Config_Repository {
2929
*
3030
* @var T
3131
*/
32-
protected array $settings = array();
32+
protected array $settings;
3333

3434
/**
3535
* Constructor
@@ -39,16 +39,14 @@ class XWC_Config implements Config_Repository {
3939
*
4040
* @throws \InvalidArgumentException If no settings are provided.
4141
*/
42-
public function __construct( array $args, protected array $defaults = array() ) {
42+
public function __construct( protected array $args, protected array $defaults = array() ) {
4343
if ( ! isset( $args['api'] ) && ! isset( $args['page'] ) ) {
4444
throw new \InvalidArgumentException(
4545
'You must provide either an WC Settings_API or a WC_Settings_Page configuration',
4646
);
4747
}
4848

49-
foreach ( $args as $type => $prefix ) {
50-
$this->parse_settings( $type, $prefix );
51-
}
49+
$this->reload();
5250
}
5351

5452
/**
@@ -227,6 +225,21 @@ protected function get_sub( string ...$keys ): mixed {
227225
return $opts;
228226
}
229227

228+
/**
229+
* Reload the config array
230+
*
231+
* @return static
232+
*/
233+
public function reload(): static {
234+
$this->settings = array();
235+
236+
foreach ( $this->args as $type => $prefix ) {
237+
$this->parse_settings( $type, $prefix );
238+
}
239+
240+
return $this;
241+
}
242+
230243
/**
231244
* Get the settings array
232245
*

src/Interfaces/Config_Repository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
* Interface describing a config repository
1313
*/
1414
interface Config_Repository {
15+
/**
16+
* Reload the config array
17+
*
18+
* @return static
19+
*/
20+
public function reload(): static;
21+
1522
/**
1623
* Get the entire config array
1724
*

0 commit comments

Comments
 (0)