src/AbstractStream.php
public function setResource($resource = 'php://temp', $mode = 'w+b')
    {
        if (is_resource($this->resource)) {
            throw new DomainException('The resource is already set.');
        }

        if (is_resource($resource)) {
            $this->resource = $resource;
        } elseif (is_string($resource)) {
            set_error_handler(function () {
                throw new Exception('Failed to open stream.');
            }, E_WARNING);
            try {
                $this->resource = fopen($resource, $mode);
            } catch (Exception $ex) {
                restore_error_handler();
                throw new InvalidArgumentException(sprintf(
                    'Invalid path "%s" specified.',
                    $resource
                ));
            }
            restore_error_handler();
        } else {
            throw new InvalidArgumentException(sprintf(
                'Invalid resource "%s" provided.',
                is_object($resource) ? get_class($resource) : gettype($resource)
            ));
        }

        return $this;
    }
public function setResource($resource = 'php://temp', $mode = 'w+b')
    {
        if (is_resource($this->resource)) {
            throw new DomainException('The resource is already set.');
        }

        if (is_resource($resource)) {
            $this->resource = $resource;
        } elseif (is_string($resource)) {
            set_error_handler(function () {
                throw new Exception('Failed to open stream.');
            }, E_WARNING);
            try {
                $this->resource = fopen($resource, $mode);
            } catch (Exception $ex) {
                restore_error_handler();
                throw new InvalidArgumentException(sprintf(
                    'Invalid path "%s" specified.',
                    $resource
                ));
            }
            restore_error_handler();
        } else {
            throw new InvalidArgumentException(sprintf(
                'Invalid resource "%s" provided.',
                is_object($resource) ? get_class($resource) : gettype($resource)
            ));
        }

        return $this;
    }
public function setResource ( $ resource = 'php://temp' , $ mode = 'w+b' ) { if ( is_resource ( $ this -> resource ) ) { throw new DomainException ( 'The resource is already set.' ) ; } if ( is_resource ( $ resource ) ) { $ this -> resource = $ resource ; } elseif ( is_string ( $ resource ) ) { set_error_handler ( function ( ) { throw new Exception ( 'Failed to open stream.' ) ; } , E_WARNING ) ; try { $ this -> resource = fopen ( $ resource , $ mode ) ; } catch ( Exception $ ex ) { restore_error_handler ( ) ; throw new InvalidArgumentException ( sprintf ( 'Invalid path "%s" specified.' , $ resource ) ) ; } restore_error_handler ( ) ; } else { throw new InvalidArgumentException ( sprintf ( 'Invalid resource "%s" provided.' , is_object ( $ resource ) ? get_class ( $ resource ) : gettype ( $ resource ) ) ) ; } return $ this ; }
Sets the resource to wrapper.

@param string|resource $resource Optional; "php://temp" by default. The
resource wrapper reference as
"scheme://target" or resource to wrap
@param string          $mode     Optional; "w+b" by default. The type of
access to the stream if the access type
is not specified for a resource

@throws \DomainException          If resource already set
@throws \InvalidArgumentException If the type of the specified resource
is not acceptable

@return self
Sets the resource to wrapper .