Skip to content

Commit bbb788c

Browse files
authored
add extra headers added
1 parent 8ba4ea2 commit bbb788c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/Formatters/JsonFormatter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class JsonFormatter implements ResponseFormatter
88
{
9-
public function __invoke(mixed $content = '', int $code = 200): string
9+
public function __invoke(mixed $content = '', int $code = 200, array &$headers = []): string
1010
{
1111
if (is_string($content)) {
1212
$content = json_validate($content)
@@ -15,6 +15,8 @@ public function __invoke(mixed $content = '', int $code = 200): string
1515

1616
}
1717

18+
$headers['Content-Type'] ='application/json';
19+
1820
return json_encode($content, JSON_UNESCAPED_UNICODE);
1921
}
2022
}

src/Providers/MacroServiceProvider.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function boot(): void
2222
*/
2323
ResponseFacade::macro('deleted',
2424
function ($content = '', array $headers = []) {
25-
return response(app('formatter')($content, Response::HTTP_OK), Response::HTTP_OK, $headers);
25+
return response(app('formatter')($content, Response::HTTP_OK, $headers), Response::HTTP_OK, $headers);
2626
});
2727

2828
/**
@@ -34,7 +34,7 @@ function ($content = '', array $headers = []) {
3434
*/
3535
ResponseFacade::macro('restored',
3636
function ($content = '', array $headers = []) {
37-
return response(app('formatter')($content, Response::HTTP_OK), Response::HTTP_OK, $headers);
37+
return response(app('formatter')($content, Response::HTTP_OK, $headers), Response::HTTP_OK, $headers);
3838
});
3939

4040
/**
@@ -46,7 +46,7 @@ function ($content = '', array $headers = []) {
4646
*/
4747
ResponseFacade::macro('created',
4848
function ($content = '', array $headers = []) {
49-
return response(app('formatter')($content, Response::HTTP_CREATED), Response::HTTP_CREATED, $headers);
49+
return response(app('formatter')($content, Response::HTTP_CREATED, $headers), Response::HTTP_CREATED, $headers);
5050
});
5151

5252
/**
@@ -58,7 +58,7 @@ function ($content = '', array $headers = []) {
5858
*/
5959
ResponseFacade::macro('updated',
6060
function ($content = '', array $headers = []) {
61-
return response(app('formatter')($content, Response::HTTP_OK), Response::HTTP_OK, $headers);
61+
return response(app('formatter')($content, Response::HTTP_OK, $headers), Response::HTTP_OK, $headers);
6262
});
6363

6464
/**
@@ -70,7 +70,7 @@ function ($content = '', array $headers = []) {
7070
*/
7171
ResponseFacade::macro('exported',
7272
function ($content = '', array $headers = []) {
73-
return response(app('formatter')($content, Response::HTTP_ACCEPTED), Response::HTTP_ACCEPTED, $headers);
73+
return response(app('formatter')($content, Response::HTTP_ACCEPTED, $headers), Response::HTTP_ACCEPTED, $headers);
7474
});
7575

7676
/**
@@ -82,7 +82,7 @@ function ($content = '', array $headers = []) {
8282
*/
8383
ResponseFacade::macro('failed',
8484
function ($content = '', array $headers = []) {
85-
return response(app('formatter')($content, Response::HTTP_BAD_REQUEST), Response::HTTP_BAD_REQUEST, $headers);
85+
return response(app('formatter')($content, Response::HTTP_BAD_REQUEST, $headers), Response::HTTP_BAD_REQUEST, $headers);
8686
});
8787

8888
/**
@@ -94,7 +94,7 @@ function ($content = '', array $headers = []) {
9494
*/
9595
ResponseFacade::macro('error',
9696
function ($content = '', array $headers = []) {
97-
return response(app('formatter')($content, Response::HTTP_INTERNAL_SERVER_ERROR), Response::HTTP_INTERNAL_SERVER_ERROR, $headers);
97+
return response(app('formatter')($content, Response::HTTP_INTERNAL_SERVER_ERROR, $headers), Response::HTTP_INTERNAL_SERVER_ERROR, $headers);
9898
});
9999

100100
/**
@@ -106,7 +106,7 @@ function ($content = '', array $headers = []) {
106106
*/
107107
ResponseFacade::macro('success',
108108
function ($content = '', array $headers = []) {
109-
return response(app('formatter')($content, Response::HTTP_OK), Response::HTTP_OK, $headers);
109+
return response(app('formatter')($content, Response::HTTP_OK, $headers), Response::HTTP_OK, $headers);
110110
});
111111

112112
/**
@@ -118,7 +118,7 @@ function ($content = '', array $headers = []) {
118118
*/
119119
ResponseFacade::macro('banned',
120120
function ($content = '', array $headers = []) {
121-
return response(app('formatter')($content, Response::HTTP_UNAUTHORIZED), Response::HTTP_UNAUTHORIZED, $headers);
121+
return response(app('formatter')($content, Response::HTTP_UNAUTHORIZED, $headers), Response::HTTP_UNAUTHORIZED, $headers);
122122
});
123123

124124
/**
@@ -130,7 +130,7 @@ function ($content = '', array $headers = []) {
130130
*/
131131
ResponseFacade::macro('forbidden',
132132
function ($content = '', array $headers = []) {
133-
return response(app('formatter')($content, Response::HTTP_FORBIDDEN), Response::HTTP_FORBIDDEN, $headers);
133+
return response(app('formatter')($content, Response::HTTP_FORBIDDEN, $headers), Response::HTTP_FORBIDDEN, $headers);
134134
});
135135

136136
/**
@@ -142,7 +142,7 @@ function ($content = '', array $headers = []) {
142142
*/
143143
ResponseFacade::macro('notfound',
144144
function ($content = '', array $headers = []) {
145-
return response(app('formatter')($content, Response::HTTP_NOT_FOUND), Response::HTTP_NOT_FOUND, $headers);
145+
return response(app('formatter')($content, Response::HTTP_NOT_FOUND, $headers), Response::HTTP_NOT_FOUND, $headers);
146146
});
147147

148148
/**
@@ -154,7 +154,7 @@ function ($content = '', array $headers = []) {
154154
*/
155155
ResponseFacade::macro('locked',
156156
function ($content = '', array $headers = []) {
157-
return response(app('formatter')($content, Response::HTTP_LOCKED), Response::HTTP_LOCKED, $headers);
157+
return response(app('formatter')($content, Response::HTTP_LOCKED, $headers), Response::HTTP_LOCKED, $headers);
158158
});
159159

160160
/**
@@ -166,7 +166,7 @@ function ($content = '', array $headers = []) {
166166
*/
167167
ResponseFacade::macro('overflow',
168168
function ($content = '', array $headers = []) {
169-
return response(app('formatter')($content, Response::HTTP_TOO_MANY_REQUESTS), Response::HTTP_TOO_MANY_REQUESTS, $headers);
169+
return response(app('formatter')($content, Response::HTTP_TOO_MANY_REQUESTS, $headers), Response::HTTP_TOO_MANY_REQUESTS, $headers);
170170
});
171171
}
172172
}

0 commit comments

Comments
 (0)