@@ -39,9 +39,7 @@ public function __construct(Request $request)
39
39
public function index (Request $ request ): JsonResponse
40
40
{
41
41
try {
42
- return $ this ->prepareResponse (
43
- $ this ->scope ->getPreferences ($ this ->group )
44
- );
42
+ return response ()->json ($ this ->scope ->getPreferences ($ this ->group ));
45
43
} catch (Throwable $ exception ) {
46
44
$ this ->handleException ($ exception );
47
45
}
@@ -50,9 +48,7 @@ public function index(Request $request): JsonResponse
50
48
public function get (Request $ request ): JsonResponse
51
49
{
52
50
try {
53
- return $ this ->prepareResponse (
54
- $ this ->scope ->getPreference ($ this ->group )
55
- );
51
+ return $ this ->prepareResponse ();
56
52
} catch (Throwable $ exception ) {
57
53
$ this ->handleException ($ exception );
58
54
}
@@ -67,9 +63,7 @@ public function update(PreferenceUpdateRequest $request): JsonResponse
67
63
68
64
$ this ->scope ->setPreference ($ this ->group , $ value );
69
65
70
- return $ this ->prepareResponse (
71
- $ this ->scope ->getPreference ($ this ->group )
72
- );
66
+ return $ this ->prepareResponse ();
73
67
} catch (Throwable $ exception ) {
74
68
return $ this ->handleException ($ exception );
75
69
}
@@ -80,9 +74,7 @@ public function delete(Request $request): JsonResponse
80
74
try {
81
75
$ this ->scope ->removePreference ($ this ->group );
82
76
83
- return $ this ->prepareResponse (
84
- $ this ->scope ->getPreference ($ this ->group )
85
- );
77
+ return $ this ->prepareResponse ();
86
78
} catch (Throwable $ exception ) {
87
79
$ this ->handleException ($ exception );
88
80
}
@@ -149,18 +141,13 @@ private function extractScopeAndGroup($routeName): array
149
141
];
150
142
}
151
143
152
- private function prepareResponse (mixed $ pref ): JsonResponse
144
+ /**
145
+ * @throws AuthorizationException
146
+ * @throws PreferenceNotFoundException
147
+ */
148
+ private function prepareResponse (): JsonResponse
153
149
{
154
- if (!empty ($ pref ) && is_object ($ pref ) && method_exists ($ pref , 'toArray ' )) {
155
- $ pref = $ pref ->toArray ();
156
- }
157
-
158
- if (!is_array ($ pref )) {
159
- $ pref = [
160
- 'value ' => $ pref ,
161
- ];
162
- }
163
- return response ()->json ($ pref );
150
+ return response ()->json ($ this ->scope ->getPreferenceDto ($ this ->group ));
164
151
}
165
152
166
153
/**
@@ -176,7 +163,7 @@ private function handleException(Throwable|\Exception $exception)
176
163
};
177
164
}
178
165
179
- private function clean (mixed &$ value )
166
+ private function clean (mixed &$ value ): void
180
167
{
181
168
if (ConfigHelper::isXssCleanEnabled ()) {
182
169
if (is_string ($ value )) {
0 commit comments