Skip to content

Commit

Permalink
migrates to JsonSerializable
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Jan 24, 2023
1 parent bf02389 commit 9ed5154
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
13 changes: 0 additions & 13 deletions src/Lemon/Contracts/Http/Jsonable.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/Lemon/Http/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Lemon\Http;

use JsonSerializable;
use Lemon\Contracts\Http\Jsonable;
use Lemon\Contracts\Http\ResponseFactory as ResponseFactoryContract;
use Lemon\Contracts\Templating\Factory as Templating;
Expand Down Expand Up @@ -55,8 +56,8 @@ public function resolve(mixed $data): Response
return $data;
}

if ($data instanceof Jsonable) {
return new JsonResponse($data->toJson());
if ($data instanceof JsonSerializable) {
return new JsonResponse($data);
}

if ($data instanceof Template) {
Expand Down
5 changes: 3 additions & 2 deletions tests/Http/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Lemon\Tests\Http;

use JsonSerializable;
use Lemon\Config\Config;
use Lemon\Contracts\Http\Jsonable;
use Lemon\Contracts\Templating\Compiler;
Expand Down Expand Up @@ -137,14 +138,14 @@ public function getExtension(): string
}
}

class SimpleJson implements Jsonable
class SimpleJson implements JsonSerializable
{
public function __construct(
private array $json
) {
}

public function toJson(): array
public function jsonSerialize(): mixed
{
return $this->json;
}
Expand Down

0 comments on commit 9ed5154

Please sign in to comment.