0 follower

Final Class Yiisoft\Yii\Debug\Api\ServerSentEventsStream

InheritanceYiisoft\Yii\Debug\Api\ServerSentEventsStream
ImplementsPsr\Http\Message\StreamInterface, Stringable

Public Properties

Hide inherited properties

Property Type Description Defined By
$buffer array Yiisoft\Yii\Debug\Api\ServerSentEventsStream

Property Details

Hide inherited properties

$buffer public property
public array $buffer = []

Method Details

Hide inherited methods

__construct() public method

public __construct( Closure $stream ): mixed
$stream Closure

                public function __construct(
    private Closure $stream,
) {
}

            
__toString() public method

public __toString( ): string

                public function __toString(): string
{
    return $this->getContents();
}

            
close() public method

public close( ): void

                public function close(): void
{
    $this->eof = true;
}

            
detach() public method

public detach( ): void

                public function detach(): void
{
    $this->eof = true;
}

            
eof() public method

public eof( ): boolean

                public function eof(): bool
{
    return $this->eof;
}

            
getContents() public method

public getContents( ): string

                public function getContents(): string
{
    return $this->read(1024);
}

            
getMetadata() public method

public getMetadata( mixed $key null ): array
$key mixed

                public function getMetadata($key = null): array
{
    return [];
}

            
getSize() public method

public getSize( ): integer

                public function getSize(): int
{
    return 0;
}

            
isReadable() public method

public isReadable( ): boolean

                public function isReadable(): bool
{
    return true;
}

            
isSeekable() public method

public isSeekable( ): boolean

                public function isSeekable(): bool
{
    return false;
}

            
isWritable() public method

public isWritable( ): boolean

                public function isWritable(): bool
{
    return false;
}

            
read() public method

TODO: support length reading

public read( integer $length ): string
$length integer

                public function read(int $length): string
{
    $continue = ($this->stream)($this->buffer);
    if (!$continue) {
        $this->eof = true;
    }
    $output = '';
    foreach ($this->buffer as $key => $value) {
        unset($this->buffer[$key]);
        $output .= sprintf("data: %s\n", $value);
    }
    $output .= "\n";
    return $output;
}

            
rewind() public method

public rewind( ): void

                public function rewind(): void
{
    throw new \RuntimeException('Stream is not seekable');
}

            
seek() public method

public seek( mixed $offset, mixed $whence SEEK_SET ): void
$offset mixed
$whence mixed

                public function seek($offset, $whence = SEEK_SET): void
{
    throw new \RuntimeException('Stream is not seekable');
}

            
tell() public method

public tell( ): integer

                public function tell(): int
{
    return 0;
}

            
write() public method

public write( mixed $string ): integer
$string mixed

                public function write($string): int
{
    throw new \RuntimeException('Stream is not writable');
}