Skip to content

Commit 3015627

Browse files
committed
Using splat for response
1 parent 8fbc7a5 commit 3015627

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/ApiProblem.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,22 @@ public function toArray(): array
221221
*
222222
* @param string[] $additional
223223
*/
224-
public function response(string|Throwable $detail, int|string $status, ?string $type = null, ?string $title = null, array $additional = []): JsonResponse
224+
public function response(...$params)
225+
// public function response(string|Throwable $detail, int|string $status, ?string $type = null, ?string $title = null, array $additional = []): JsonResponse
225226
{
226-
$apiProblem = new ApiProblem($status, $detail, $type, $title, $additional);
227+
$apProblem = null;
228+
229+
print_r($params);die();
230+
231+
if ($this->getStatus()) {
232+
// Use current object
233+
$apProblem = $this;
234+
} else {
235+
// Called from a Facade, use local object
236+
$apiProblem = new ApiProblem();
237+
}
238+
239+
$apiProblem = ($this->getStatus()) ? $this : new ApiProblem($status, $detail, $type, $title, $additional);
227240

228241
return response()
229242
->json($apiProblem->toArray(), $apiProblem->getStatus())

0 commit comments

Comments
 (0)