Final Class Yiisoft\Db\Schema\Data\StringableStream
| Inheritance | Yiisoft\Db\Schema\Data\StringableStream |
|---|---|
| Implements | Stringable |
Represents a resource stream to be used as a Stringable value.
use Yiisoft\Db\Schema\Data\ResourceStream;
// @var resource $resource
$stream = new StringableStream($resource);
echo $stream;
Public Methods
Method Details
| public __construct( resource $value ): mixed | ||
| $value | resource |
The open resource stream. |
public function __construct(mixed $value)
{
$this->value = $value;
}
Closes the resource.
| public __destruct( ): mixed |
public function __destruct()
{
if (is_resource($this->value)) {
fclose($this->value);
}
}
| public __serialize( ): string[] | ||
| return | string[] |
Prepared values for serialization. |
|---|---|---|
public function __serialize(): array
{
return ['value' => $this->__toString()];
}
| public __toString( ): string | ||
| return | string |
The result of reading the resource stream. |
|---|---|---|
public function __toString(): string
{
/**
* @psalm-suppress PossiblyFalsePropertyAssignmentValue, PossiblyInvalidArgument
* @var string
*/
return match (gettype($this->value)) {
GettypeResult::RESOURCE => $this->value = stream_get_contents($this->value),
GettypeResult::RESOURCE_CLOSED => throw new LogicException('Resource is closed.'),
default => $this->value,
};
}
Signup or Login in order to comment.