public static function factory($resource = '', $size = null)
    {
        $type = gettype($resource);

        if ($type == 'string') {
            $stream = fopen('php://temp', 'r+');
            if ($resource !== '') {
                fwrite($stream, $resource);
                fseek($stream, 0);
            }
            return new self($stream);
        }

        if ($type == 'resource') {
            return new self($resource, $size);
        }

        if ($resource instanceof StreamInterface) {
            return $resource;
        }

        if ($type == 'object' && method_exists($resource, '__toString')) {
            return self::factory((string) $resource, $size);
        }

        throw new \InvalidArgumentException('Invalid resource type: ' . $type);
    }
public static function factory($resource = '', $size = null)
    {
        $type = gettype($resource);

        if ($type == 'string') {
            $stream = fopen('php://temp', 'r+');
            if ($resource !== '') {
                fwrite($stream, $resource);
                fseek($stream, 0);
            }
            return new self($stream);
        }

        if ($type == 'resource') {
            return new self($resource, $size);
        }

        if ($resource instanceof StreamInterface) {
            return $resource;
        }

        if ($type == 'object' && method_exists($resource, '__toString')) {
            return self::factory((string) $resource, $size);
        }

        throw new \InvalidArgumentException('Invalid resource type: ' . $type);
    }
public static function factory ( $ resource = '' , $ size = null ) { $ type = gettype ( $ resource ) ; if ( $ type == 'string' ) { $ stream = fopen ( 'php://temp' , 'r+' ) ; if ( $ resource !== '' ) { fwrite ( $ stream , $ resource ) ; fseek ( $ stream , 0 ) ; } return new self ( $ stream ) ; } if ( $ type == 'resource' ) { return new self ( $ resource , $ size ) ; } if ( $ resource instanceof StreamInterface ) { return $ resource ; } if ( $ type == 'object' && method_exists ( $ resource , '__toString' ) ) { return self :: factory ( ( string ) $ resource , $ size ) ; } throw new \ InvalidArgumentException ( 'Invalid resource type: ' . $ type ) ; }
Create a new stream based on the input type

@param resource|string|StreamInterface $resource Entity body data
@param int                             $size     Size of the data contained in the resource

@return Stream
@throws \InvalidArgumentException if the $resource arg is not valid.
Create a new stream based on the input type