contents = $contents; } public function getStream(): StreamInterface { $resource = fopen('php://temp', 'r+'); if ($resource === false) { throw new RuntimeException("Could not open temp."); } fwrite($resource, $this->getString()); rewind($resource); return new Stream($resource); } public function getString(): string { return $this->contents; } public function getLength(): int { return strlen($this->contents); } public static function createFromString(string $contents): ContentsString { $obj = new self($contents); return $obj; } }