File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,6 @@ public static function settings(bool $getShared = true): Settings
2929 return static ::getSharedInstance ('settings ' );
3030 }
3131
32- return new Settings ();
32+ return new Settings (config ( ' Settings ' ) );
3333 }
3434}
Original file line number Diff line number Diff line change 22
33namespace Sparks \Settings ;
44
5+ use Sparks \Settings \Config \Settings as SettingsConfig ;
6+
57/**
68 * Allows developers a single location to store and
79 * retrieve settings that were original set in config files
@@ -27,18 +29,21 @@ class Settings
2729 /**
2830 * Grabs instances of our handlers.
2931 */
30- public function __construct ()
32+ public function __construct (? SettingsConfig $ config = null )
3133 {
32- foreach (config ('Settings ' )->handlers as $ handler ) {
33- $ class = config ('Settings ' )->{$ handler }['class ' ] ?? null ;
34+ /** @var SettingsConfig $config */
35+ $ config = $ config ?? config ('Settings ' );
36+
37+ foreach ($ config ->handlers as $ handler ) {
38+ $ class = $ config ->{$ handler }['class ' ] ?? null ;
3439
3540 if ($ class === null ) {
3641 continue ;
3742 }
3843
3944 $ this ->handlers [$ handler ] = new $ class ();
4045
41- $ writeable = config ( ' Settings ' ) ->{$ handler }['writeable ' ] ?? null ;
46+ $ writeable = $ config ->{$ handler }['writeable ' ] ?? null ;
4247
4348 if ($ writeable ) {
4449 $ this ->writeHandler = $ handler ;
Original file line number Diff line number Diff line change @@ -16,6 +16,17 @@ final class SettingsTest extends TestCase
1616{
1717 use DatabaseTestTrait;
1818
19+ public function testSettingsUsesParameter ()
20+ {
21+ $ config = config ('Settings ' );
22+ $ config ->handlers = [];
23+
24+ $ settings = new Settings ($ config );
25+ $ result = $ this ->getPrivateProperty ($ settings , 'handlers ' );
26+
27+ $ this ->assertSame ([], $ result );
28+ }
29+
1930 public function testSettingsGetsFromConfig ()
2031 {
2132 $ settings = new Settings ();
You can’t perform that action at this time.
0 commit comments