Final Class Yiisoft\DataResponse\DataStream\DataStream
| Inheritance | Yiisoft\DataResponse\DataStream\DataStream |
|---|---|
| Implements | Psr\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.
Public Methods
Method Details
| 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,
) {}
| public __toString( ): string |
public function __toString(): string
{
return (string) $this->getFormatted();
}
Changes the data.
| public changeData( mixed $data ): void | ||
| $data | mixed |
The new data. |
public function changeData(mixed $data): void
{
$this->data = $data;
$this->resetState();
}
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();
}
| public getContents( ): string |
public function getContents(): string
{
return $this->getFormatted()->getContents();
}
Returns the raw data.
| public getData( ): mixed | ||
| return | mixed |
The raw data. |
|---|---|---|
public function getData(): mixed
{
return $this->data;
}
Returns the formatter.
| public getFormatter( ): Yiisoft\DataResponse\Formatter\FormatterInterface|null | ||
| return | Yiisoft\DataResponse\Formatter\FormatterInterface|null |
The formatter or |
|---|---|---|
public function getFormatter(): ?FormatterInterface
{
return $this->formatter;
}
| public getMetadata( string|null $key = null ): mixed | ||
| $key | string|null | |
public function getMetadata(?string $key = null)
{
return $this->getFormatted()->getMetadata($key);
}
| public getSize( ): integer|null |
public function getSize(): ?int
{
return $this->getFormatted()->getSize();
}
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;
}
| public isReadable( ): boolean |
public function isReadable(): bool
{
return $this->getFormatted()->isReadable();
}
| public isSeekable( ): boolean |
public function isSeekable(): bool
{
return $this->getFormatted()->isSeekable();
}
| public isWritable( ): boolean |
public function isWritable(): bool
{
return $this->getFormatted()->isWritable();
}
| public read( integer $length ): string | ||
| $length | integer | |
public function read(int $length): string
{
return $this->getFormatted()->read($length);
}
| 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);
}
Signup or Login in order to comment.