index/src/Http/Content/StringContent.php

37 lines
825 B
PHP

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