@param StreamInterface|resource|string|null $body

@return StreamInterface
19921
public static function stream($body = null): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_resource($body)) {
            return new Stream($body);
        }

        $resource = \fopen('php://temp', 'rw+b');
        $stream = new Stream($resource);
        if ($body) {
            $stream->write($body);
        }

        return $stream;
    }
358976
public function build(): TakeResponseBodyAsStreamRequest
	{
		$instance = new TakeResponseBodyAsStreamRequest();
		if ($this->requestId === null) {
			throw new BuilderException('Property [requestId] is required.');
		}
		$instance->requestId = $this->requestId;
		return $instance;
	}
1210647
public function getBody()
    {
        if (!$this->_body instanceof StreamInterface) {
            if ($this->_body === null) {
                $body = $this->defaultBody();
            } elseif ($this->_body instanceof \Closure) {
                $body = \call_user_func($this->_body, $this);
            } else {
                $body = $this->_body;
            }

            $this->_body = Yii::ensureObject($body, StreamInterface::class);
        }
        return $this->_body;
    }
522867
public function setStream(StreamInterface $stream = null)
    {
        $this->stream = $stream;
        $this->decodedStream = null;
        $this->charsetStream = null;
    }
267105
public function createRequest(string $method, string $uri, array $body = []): RequestInterface
    {
        $request = $this->requestFactory->createRequest($method, $uri)
            ->withHeader('Content-Type', 'application/json')
            ->withHeader('Authorization', 'Token ' . $this->token)
            ->withHeader('X-Secret', $this->secret)
        ;

        if (!empty($body)) {
            $request = $request
                ->withBody($this->streamFactory->createStream(json_encode($body, JSON_UNESCAPED_UNICODE)))
            ;
        }

        return $request;
    }
374973
public static function streamed(callable $callback = null, $status = ResponseHeader::HTTP_OK, $headers = [])
    {
        return new StreamedResponse($callback, $status, $headers);
    }
1228716
public function withBody(StreamInterface $body)
    {
        if ($this->complete) {
            return $this;
        }

        $new = $this->psrResponse->withBody($body);
        return new self($new);
    }
185030
protected function castStream($source): StreamInterface
    {
        if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) {
            $source = $source->getStream();
        }

        if ($source instanceof StreamInterface) {
            //This step is important to prevent user errors
            $source->rewind();

            return $source;
        }

        if (is_resource($source)) {
            return stream_for($source);
        }

        if (empty($source)) {
            //Guzzle?
            return stream_for('');
        }

        if ($this->isFilename($source)) {
            //Must never pass user string in here, use Stream
            return stream_for(fopen($source, 'rb'));
        }

        //We do not allow source names in a string form
        throw new BucketException(
            "Source must be a valid resource, stream or filename, invalid value given"
        );
    }
1350277
public function run(): StreamInterface
    {
        // Extract some important objects
        $router = $this->container('router');
        $request = $this->container('request');
        $response = $this->container('response');

        // Get current matched route with and extract variables with callback
        $route = $router->getRoute();

        return $this->exec($route, $request, $response);
    }
974792
public function getStream($context = null)
	{
		$this->requestBody();
		if (is_null($context)) {
			return fopen($this->bodyTempFile, 'rb', false);
		} else {
			return fopen($this->bodyTempFile, 'rb', false, $context);
		}
	}
468391
public function createDocBlock($body = NULL) {
    $block = new DocBlock($body);
    $this->setDocBlock($block);
    return $block;
  }
1334947
public function response($body = null): ResponseInterface
    {
        /* RFC2616 - 14.18 says all Responses need to have a Date */
        if (!$this->header->has('Date')) {
            $this->setDate(\DateTime::createFromFormat('U', (string) \time()));
        }

        if (($this->status >= 100 && $this->status < 200) || $this->status === 204 || $this->status === 304) {
            $body = null;
            $this->header->remove('Content-Type');
            $this->header->remove('Content-Length');
        } else {
            if ($this->header->has('Transfer-Encoding')) {
                $this->header->remove('Content-Length');
            }

            if ($this->request->method() === 'HEAD') {
                $body = null;
            }
        }

        if (!$this->version && 'HTTP/1.0' !== $this->request->server('SERVER_PROTOCOL')) {
            $this->version = '1.1';
        }

        // Check if we need to send extra expire info headers
        if ('1.0' === $this->version && false !== strpos($this->getHeaderLine('Cache-Control') ?? '', 'no-cache')) {
            $this->header->set('Pragma', 'no-cache');
            $this->header->set('Expires', -1);
        }

        // Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
        if (
            true === $this->request->secure() &&
            false !== \stripos($this->getHeaderLine('Content-Disposition') ?? '', 'attachment') &&
            \preg_match('/MSIE (.*?);/i', $this->request->header('User-Agent'), $match) === 1
        ) {
            if ((int) \preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) {
                $this->header->remove('Cache-Control');
            }
        }

        $headers = $this->header->all();
        $this->cookie->inject($headers);

        return Factory::response($this->status, $body, $headers, $this->version, $this->reason);
    }
1345683
public function createComment($body = null)
    {
        list($response, $statusCode, $httpHeader) = $this->createCommentWithHttpInfo ($body);
        return $response; 
    }
1297672
public function getBody()
    {
        $streamResource = fopen('php://memory', 'r+');
        if (is_resource($this->content)) {
            stream_copy_to_stream($this->content, $streamResource);
        } else {
            fwrite($streamResource, $this->content);
        }
        rewind($streamResource);

        return new ContentStream($streamResource);
    }
1329818
public static function createFromRequest(StreamInterface $stream, ServerRequestInterface $request = null)
    {
        $result = [];
        if ($request === null) {
            $headers = \tao_helpers_Http::getHeaders();
            $rangeHeader = isset($headers['Range']) ? [$headers['Range']] : null;
        } else {
            $rangeHeader = $request->hasHeader('Range') ? $request->getHeader('Range') : null;
        }
        if ($rangeHeader) {
            $ranges = explode(',', $rangeHeader[0]);
            foreach($ranges as $range) {
                $range = str_replace('bytes=', '', $range);
                $result[] = new StreamRange($stream, $range);
            }
        }
        return $result;
    }
1035479
private function addDebugToolBar(StreamInterface $body){
        $newBody    = new \Fratily\Http\Message\Stream\MemoryStream();

        $body->rewind();
        $newBody->write($this->debugbar->embed($body->getContents()));

        return $newBody;
    }
1063748
protected function createStream($socket, RequestInterface $request, ResponseInterface $response): Stream
    {
        $size = null;

        if ($response->hasHeader('Content-Length')) {
            $size = (int) $response->getHeaderLine('Content-Length');
        }

        return new Stream($request, $socket, $size);
    }