index/src/Http/Content/StreamContent.php

37 lines
783 B
PHP

<?php
// StreamContent.php
// Created: 2022-02-10
// Updated: 2022-02-27
namespace Index\Http\Content;
use Stringable;
use Index\IO\Stream;
use Index\IO\FileStream;
class StreamContent implements Stringable, IHttpContent {
private Stream $stream;
public function __construct(Stream $stream) {
$this->stream = $stream;
}
public function getStream(): Stream {
return $this->stream;
}
public function __toString(): string {
return (string)$this->stream;
}
public static function fromFile(string $path): StreamContent {
return new StreamContent(
FileStream::openRead($path)
);
}
public static function fromRequest(): StreamContent {
return self::fromFile('php://input');
}
}