src/Diagnostics/ContentWriter.php
public function saveAsHandler()
    {
        $this->handler = tmpfile();
        if (false === $this->handler) {
            throw new SdkException('Unable to create a handler for tempfile in ' . sys_get_temp_dir());
        }
        if (empty($this->handler)) {
            throw new SdkException('Handler has an invalid state. It is empty.');
        }
        $this->tempPath = $this->getPathFromHandler();
        if (empty($this->tempPath)) {
            throw new SdkException('Unable to locate path from stream source');
        }
        $result = fwrite($this->handler, $this->getContent());
        if (false === $result) {
            throw new SdkException('Unable to write content into temp file: ' . $this->getTempPath());
        }
        if (empty($result)) {
            throw new SdkException('Empty or zero file was received: ' . $this->getTempPath());
        }
        if (-1 === fseek($this->handler, 0)) {
            throw new SdkException('Unable to reset file pointer in the file ' . $this->getTempPath());
        }
        $this->bytes = $result;
    }
public function saveAsHandler()
    {
        $this->handler = tmpfile();
        if (false === $this->handler) {
            throw new SdkException('Unable to create a handler for tempfile in ' . sys_get_temp_dir());
        }
        if (empty($this->handler)) {
            throw new SdkException('Handler has an invalid state. It is empty.');
        }
        $this->tempPath = $this->getPathFromHandler();
        if (empty($this->tempPath)) {
            throw new SdkException('Unable to locate path from stream source');
        }
        $result = fwrite($this->handler, $this->getContent());
        if (false === $result) {
            throw new SdkException('Unable to write content into temp file: ' . $this->getTempPath());
        }
        if (empty($result)) {
            throw new SdkException('Empty or zero file was received: ' . $this->getTempPath());
        }
        if (-1 === fseek($this->handler, 0)) {
            throw new SdkException('Unable to reset file pointer in the file ' . $this->getTempPath());
        }
        $this->bytes = $result;
    }
Writes content into temporary file and returns open handler to it.
The temporary file is removed when closed (e.g. by calling fclose()) or
there are no more references (e.g. variables) or with script termination.
@throws SdkException