Skip to content

Commit

Permalink
Only parse Arrayable on output.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 19, 2020
1 parent bace921 commit c60f905
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ public static function make($message, $id = null)
public function __toString()
{
$id = ! \is_null($this->id) ? "id: {$this->id}\n" : '';
$data = 'data: '.\json_encode($this->message)."\n\n";

return sprintf("%sdata: %s\n\n", $id, \json_encode($this->message));
$payload = $this->message instanceof Arrayable
? $this->message->toArray()
: \json_encode($this->message);

return sprintf("%sdata: %s\n\n", $id, $payload);
}
}
6 changes: 1 addition & 5 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Katsana\Prefetch;

use Illuminate\Contracts\Support\Arrayable;

abstract class Handler
{
/**
Expand All @@ -13,9 +11,7 @@ abstract class Handler
*/
public function transform($data): Data
{
return Data::make(
$data instanceof Arrayable ? $data->toArray() : $data
);
return Data::make($data);
}

/**
Expand Down

0 comments on commit c60f905

Please sign in to comment.