Added posibility to create "in memory" documents

Open writer with openToMemory(), then close it with closeAndGetStream() which will return the stream pointer. After that you have to do fclose() on that pointer.
This commit is contained in:
colorful-bubbles 2018-11-11 21:28:56 +01:00 committed by GitHub
parent e99c80b3ad
commit e5c88e899c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,6 +142,33 @@ abstract class WriterAbstract implements WriterInterface
return $this; return $this;
} }
public function openToMemory()
{
$this->filePointer = $this->globalFunctionsHelper->fopen('php://temp', 'r+');
$this->throwIfFilePointerIsNotAvailable();
$this->openWriter();
$this->isWriterOpened = true;
return $this;
}
public function closeAndGetStream()
{
if (!$this->isWriterOpened) {
return;
}
$this->closeWriter();
$this->isWriterOpened = false;
rewind($this->filePointer);
fpassthru($this->filePointer);
return $this->filePointer;
}
/** /**
* Checks if the pointer to the file/stream to write to is available. * Checks if the pointer to the file/stream to write to is available.