public static function create($body = ''): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_string($body)) {
            $resource = \fopen('php://temp', 'rw+');
            \fwrite($resource, $body);
            $body = $resource;
        }

        if (\is_resource($body)) {
            $new = new self();
            $new->stream = $body;
            $meta = \stream_get_meta_data($new->stream);
            $new->seekable = $meta['seekable'];
            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
            $new->uri = $new->getMetadata('uri');

            return $new;
        }

        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
    }
public static function create($body = ''): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_string($body)) {
            $resource = \fopen('php://temp', 'rw+');
            \fwrite($resource, $body);
            $body = $resource;
        }

        if (\is_resource($body)) {
            $new = new self();
            $new->stream = $body;
            $meta = \stream_get_meta_data($new->stream);
            $new->seekable = $meta['seekable'];
            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
            $new->uri = $new->getMetadata('uri');

            return $new;
        }

        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
    }
public static function create ( $ body = '' ) : StreamInterface { if ( $ body instanceof StreamInterface ) { return $ body ; } if ( \ is_string ( $ body ) ) { $ resource = \ fopen ( 'php://temp' , 'rw+' ) ; \ fwrite ( $ resource , $ body ) ; $ body = $ resource ; } if ( \ is_resource ( $ body ) ) { $ new = new self ( ) ; $ new -> stream = $ body ; $ meta = \ stream_get_meta_data ( $ new -> stream ) ; $ new -> seekable = $ meta [ 'seekable' ] ; $ new -> readable = isset ( self :: READ_WRITE_HASH [ 'read' ] [ $ meta [ 'mode' ] ] ) ; $ new -> writable = isset ( self :: READ_WRITE_HASH [ 'write' ] [ $ meta [ 'mode' ] ] ) ; $ new -> uri = $ new -> getMetadata ( 'uri' ) ; return $ new ; } throw new \ InvalidArgumentException ( 'First argument to Stream::create() must be a string, resource or StreamInterface.' ) ; }
Creates a new PSR-7 stream.

@param string|resource|StreamInterface $body

@return StreamInterface

@throws \InvalidArgumentException
Creates a new PSR - 7 stream .