src/StorageBucket.php
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"
        );
    }
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"
        );
    }
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" ) ; }
Cast stream associated with origin data.

@param string|StreamInterface|resource $source

@return StreamInterface
Cast stream associated with origin data .