Creates a new PSR-7 stream.
Parameters
$bodystring|resource|WordPressAiClientDependenciesPsrHttpMessageStreamInterfaceoptionalDefault:
''
Source
public static function create($body = ''): StreamInterface
{
if ($body instanceof StreamInterface) {
return $body;
}
if (\is_string($body)) {
if (200000 <= \strlen($body)) {
$body = self::openZvalStream($body);
} else {
$resource = \fopen('php://memory', 'r+');
\fwrite($resource, $body);
\fseek($resource, 0);
$body = $resource;
}
}
if (!\is_resource($body)) {
throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface');
}
return new self($body);
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.