6
6
7
7
use Elegantly \Settings \Facades \Settings ;
8
8
use Elegantly \Settings \Models \Setting ;
9
+ use Illuminate \Contracts \Support \Arrayable ;
9
10
use Illuminate \Database \Eloquent \Collection ;
10
11
11
- abstract class NamespacedSettings
12
+ /**
13
+ * @implements Arrayable<string, mixed>
14
+ */
15
+ abstract class NamespacedSettings implements Arrayable
12
16
{
13
17
final public function __construct ()
14
18
{
@@ -17,16 +21,14 @@ final public function __construct()
17
21
18
22
public static function get (): static
19
23
{
20
- return static :: make () ;
24
+ return new static ;
21
25
}
22
26
23
27
abstract public static function getNamespace (): string ;
24
28
25
29
public function load (): static
26
30
{
27
- return $ this ->fill (
28
- Settings::only ($ this ->getNamespace ())
29
- );
31
+ return $ this ->fill (Settings::only ($ this ->getNamespace ()));
30
32
}
31
33
32
34
/**
@@ -43,12 +45,10 @@ public function fill(Collection $settings): static
43
45
return $ setting ->namespace === $ namespace && $ setting ->name === $ name ;
44
46
});
45
47
46
- if (! $ setting ) {
47
- continue ;
48
+ if ($ setting ) {
49
+ $ this ->{ $ name } = $ setting -> value ;
48
50
}
49
51
50
- $ this ->{$ name } = $ setting ->value ;
51
-
52
52
}
53
53
54
54
return $ this ;
@@ -74,4 +74,12 @@ public function save(): static
74
74
return $ this ;
75
75
76
76
}
77
+
78
+ /**
79
+ * @return array<string, mixed>
80
+ */
81
+ public function toArray (): array
82
+ {
83
+ return get_object_vars ($ this );
84
+ }
77
85
}
0 commit comments