0 follower

Final Class Yiisoft\Db\Schema\Data\StringableStream

InheritanceYiisoft\Db\Schema\Data\StringableStream
ImplementsStringable

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;

Method Details

Hide inherited methods

__construct() public method

public __construct( resource $value ): mixed
$value resource

The open resource stream.

                public function __construct(mixed $value)
{
    $this->value = $value;
}

            
__destruct() public method

Closes the resource.

public __destruct( ): mixed

                public function __destruct()
{
    if (is_resource($this->value)) {
        fclose($this->value);
    }
}

            
__serialize() public method

public __serialize( ): string[]
return string[]

Prepared values for serialization.

                public function __serialize(): array
{
    return ['value' => $this->__toString()];
}

            
__toString() public method

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,
    };
}

            
getValue() public method

public getValue( ): resource|string
return resource|string

The resource stream or the result of reading the stream.

                public function getValue(): mixed
{
    return $this->value;
}