Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Guide.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sajya\Server;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use ReflectionClass;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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))
Expand Down