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 {@see \LogicException} will be thrown.
Public Methods
Method Details
| public mixed __construct ( mixed $data, Yiisoft\DataResponse\Formatter\FormatterInterface|null $formatter = null ) | ||
| $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 string __toString ( ) |
public function __toString(): string
{
return (string) $this->getFormatted();
}
Changes the data.
| public void changeData ( mixed $data ) | ||
| $data | mixed |
The new data. |
public function changeData(mixed $data): void
{
$this->data = $data;
$this->resetState();
}
Changes the formatter.
| public void changeFormatter ( Yiisoft\DataResponse\Formatter\FormatterInterface $formatter ) | ||
| $formatter | Yiisoft\DataResponse\Formatter\FormatterInterface |
The new formatter. |
public function changeFormatter(FormatterInterface $formatter): void
{
$this->formatter = $formatter;
$this->resetState();
}
| public string getContents ( ) |
public function getContents(): string
{
return $this->getFormatted()->getContents();
}
Returns the raw data.
| public mixed getData ( ) | ||
| return | mixed |
The raw data. |
|---|---|---|
public function getData(): mixed
{
return $this->data;
}
Returns the formatter.
| public Yiisoft\DataResponse\Formatter\FormatterInterface|null getFormatter ( ) | ||
| return | Yiisoft\DataResponse\Formatter\FormatterInterface|null |
The formatter or |
|---|---|---|
public function getFormatter(): ?FormatterInterface
{
return $this->formatter;
}
| public mixed getMetadata ( ?string $key = null ) | ||
| $key | ?string | |
public function getMetadata(?string $key = null)
{
return $this->getFormatted()->getMetadata($key);
}
| public ?int getSize ( ) |
public function getSize(): ?int
{
return $this->getFormatted()->getSize();
}
Checks whether a formatter has been set.
| public boolean hasFormatter ( ) | ||
| return | boolean |
Whether a formatter is set. |
|---|---|---|
public function hasFormatter(): bool
{
return $this->formatter !== null;
}
| public boolean isReadable ( ) |
public function isReadable(): bool
{
return $this->getFormatted()->isReadable();
}
| public boolean isSeekable ( ) |
public function isSeekable(): bool
{
return $this->getFormatted()->isSeekable();
}
| public boolean isWritable ( ) |
public function isWritable(): bool
{
return $this->getFormatted()->isWritable();
}
| public string read ( integer $length ) | ||
| $length | integer | |
public function read(int $length): string
{
return $this->getFormatted()->read($length);
}
| public void seek ( integer $offset, integer $whence = SEEK_SET ) | ||
| $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.