protected function attach($stream)
    {
        if (is_resource($stream) === false) {
            throw new InvalidArgumentException(__METHOD__ . ' argument must be a valid PHP resource');
        }

        if (is_resource($this->stream) === true) {
            $this->detach();
        }

        $this->stream = $stream;
    }