0 follower

Final Class Yiisoft\DataResponse\DataStream\DataStream

InheritanceYiisoft\DataResponse\DataStream\DataStream
ImplementsPsr\Http\Message\StreamInterface

A lazy stream that formats data only when it's being read.

This stream wraps formatted content (string or stream) and provides methods to change the data or formatter dynamically.

A formatter must be set before reading the stream, otherwise a LogicException will be thrown.

Method Details

Hide inherited methods

__construct() public method

public __construct( mixed $data, Yiisoft\DataResponse\Formatter\FormatterInterface|null $formatter null ): mixed
$data mixed

The raw data to be formatted.

$formatter Yiisoft\DataResponse\Formatter\FormatterInterface|null

The formatter to use.

                public function __construct(
    private mixed $data,
    private ?FormatterInterface $formatter = null,
) {}

            
__toString() public method

public __toString( ): string

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

            
changeData() public method

Changes the data.

public changeData( mixed $data ): void
$data mixed

The new data.

                public function changeData(mixed $data): void
{
    $this->data = $data;
    $this->resetState();
}

            
changeFormatter() public method

Changes the formatter.

public changeFormatter( Yiisoft\DataResponse\Formatter\FormatterInterface $formatter ): void
$formatter Yiisoft\DataResponse\Formatter\FormatterInterface

The new formatter.

                public function changeFormatter(FormatterInterface $formatter): void
{
    $this->formatter = $formatter;
    $this->resetState();
}

            
close() public method

public close( ): void

                public function close(): void
{
    $this->getFormatted()->close();
}

            
detach() public method

public detach( ): mixed

                public function detach()
{
    return $this->getFormatted()->detach();
}

            
eof() public method

public eof( ): boolean

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

            
getContents() public method

public getContents( ): string

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

            
getData() public method

Returns the raw data.

public getData( ): mixed
return mixed

The raw data.

                public function getData(): mixed
{
    return $this->data;
}

            
getFormatter() public method

Returns the formatter.

public getFormatter( ): Yiisoft\DataResponse\Formatter\FormatterInterface|null
return Yiisoft\DataResponse\Formatter\FormatterInterface|null

The formatter or null if not set.

                public function getFormatter(): ?FormatterInterface
{
    return $this->formatter;
}

            
getMetadata() public method

public getMetadata( string|null $key null ): mixed
$key string|null

                public function getMetadata(?string $key = null)
{
    return $this->getFormatted()->getMetadata($key);
}

            
getSize() public method

public getSize( ): integer|null

                public function getSize(): ?int
{
    return $this->getFormatted()->getSize();
}

            
hasFormatter() public method

Checks whether a formatter has been set.

public hasFormatter( ): boolean
return boolean

Whether a formatter is set.

                public function hasFormatter(): bool
{
    return $this->formatter !== null;
}

            
isReadable() public method

public isReadable( ): boolean

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

            
isSeekable() public method

public isSeekable( ): boolean

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

            
isWritable() public method

public isWritable( ): boolean

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

            
read() public method

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

                public function read(int $length): string
{
    return $this->getFormatted()->read($length);
}

            
rewind() public method

public rewind( ): void

                public function rewind(): void
{
    $this->getFormatted()->rewind();
}

            
seek() public method

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

                public function seek(int $offset, int $whence = SEEK_SET): void
{
    $this->getFormatted()->seek($offset, $whence);
}

            
tell() public method

public tell( ): integer

                public function tell(): int
{
    return $this->getFormatted()->tell();
}

            
write() public method

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

                public function write(string $string): int
{
    return $this->getFormatted()->write($string);
}