Hello,
What version and license of phpdocx are you using?
in-memory documents and zipstream are compatible with the CreateDocxFromTemplate class, that includes the replaceVariableByText method. On https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents you can read the methods an classes that support working with in-memory documents.
Regards.