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
8 changes: 5 additions & 3 deletions src/StreamJsonEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class StreamJsonEncoder extends AbstractJsonEncoder
{
/** @var callable|null The stream callable */
/** @var callable|resource|null Write stream */
private $stream;

/** @var int Number of bytes written in the current step */
Expand All @@ -28,9 +28,9 @@ class StreamJsonEncoder extends AbstractJsonEncoder
* will simply output the json using an echo statement.
*
* @param mixed $value The value to encode as JSON
* @param callable|null $stream An optional stream to pass the output or null to echo it
* @param callable|resource|null $stream An optional stream to pass the output or null to echo it
*/
public function __construct($value, callable $stream = null)
public function __construct($value, $stream = null)
{
parent::__construct($value);

Expand Down Expand Up @@ -86,6 +86,8 @@ protected function write($string, $token)
{
if ($this->stream === null) {
echo $string;
} elseif (is_resource($this->stream)) {
fwrite($this->stream, $string);
} else {
$callback = $this->stream;
$callback($string, $token);
Expand Down