private function setStream($stream, $mode = 'r')
    {
        $error    = null;
        $resource = $stream;

        if (is_string($stream)) {
            set_error_handler(function ($e) use (&$error) {
                $error = $e;
            }, E_WARNING);
            $resource = fopen($stream, $mode);
            restore_error_handler();
        }

        if ($error) {
            throw new InvalidArgumentException('Invalid stream reference provided');
        }

        if (! is_resource($resource) || 'stream' !== get_resource_type($resource)) {
            throw new InvalidArgumentException(
                'Invalid stream provided; must be a string stream identifier or stream resource'
            );
        }

        if ($stream !== $resource) {
            $this->stream = $stream;
        }

        $this->resource = $resource;
    }
private function setStream($stream, $mode = 'r')
    {
        $error    = null;
        $resource = $stream;

        if (is_string($stream)) {
            set_error_handler(function ($e) use (&$error) {
                $error = $e;
            }, E_WARNING);
            $resource = fopen($stream, $mode);
            restore_error_handler();
        }

        if ($error) {
            throw new InvalidArgumentException('Invalid stream reference provided');
        }

        if (! is_resource($resource) || 'stream' !== get_resource_type($resource)) {
            throw new InvalidArgumentException(
                'Invalid stream provided; must be a string stream identifier or stream resource'
            );
        }

        if ($stream !== $resource) {
            $this->stream = $stream;
        }

        $this->resource = $resource;
    }
private function setStream ( $ stream , $ mode = 'r' ) { $ error = null ; $ resource = $ stream ; if ( is_string ( $ stream ) ) { set_error_handler ( function ( $ e ) use ( & $ error ) { $ error = $ e ; } , E_WARNING ) ; $ resource = fopen ( $ stream , $ mode ) ; restore_error_handler ( ) ; } if ( $ error ) { throw new InvalidArgumentException ( 'Invalid stream reference provided' ) ; } if ( ! is_resource ( $ resource ) || 'stream' !== get_resource_type ( $ resource ) ) { throw new InvalidArgumentException ( 'Invalid stream provided; must be a string stream identifier or stream resource' ) ; } if ( $ stream !== $ resource ) { $ this -> stream = $ stream ; } $ this -> resource = $ resource ; }
Set the internal stream resource.

@param string|resource $stream String stream target or stream resource.
@param string $mode Resource mode for stream target.
@throws InvalidArgumentException for invalid streams or resources.
Set the internal stream resource .