diff --git a/src/Guide.php b/src/Guide.php index 10436b7..fa97583 100644 --- a/src/Guide.php +++ b/src/Guide.php @@ -4,6 +4,7 @@ namespace Sajya\Server; +use Illuminate\Http\JsonResponse; use Illuminate\Support\Collection; use Illuminate\Support\Str; use ReflectionClass; @@ -40,9 +41,9 @@ public function __construct(array $procedures = []) /** * @param string $content * - * @return string + * @return JsonResponse */ - public function handle(string $content = ''): string + public function handle(string $content = ''): JsonResponse { $parser = new Parser($content); @@ -55,7 +56,7 @@ public function handle(string $content = ''): string $response = $parser->isBatch() ? $result->all() : $result->first(); - return json_encode($response, JSON_THROW_ON_ERROR, 512); + return response()->json($response); } /** @@ -109,6 +110,10 @@ public function findProcedure(Request $request): ?string $class = Str::beforeLast($request->getMethod(), '@'); $method = Str::afterLast($request->getMethod(), '@'); + if (Str::contains($request->getMethod(), '@') === false) { + $method = 'handle'; + } + return $this->map ->filter(fn (string $procedure) => $this->getProcedureName($procedure) === $class) ->filter(fn (string $procedure) => $this->checkExistPublicMethod($procedure, $method))