array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Styles', 'xml' => '{toReplace}'),
'document' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Document', 'xml' => '{toReplace}'),
'footnotes' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Footnotes', 'xml' => '{toReplace}'),
'endnotes' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Endnotes', 'xml' => '{toReplace}'),
'settings' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Settings', 'xml' => '{toReplace}'),
);
/**
* Builds a PhpWord instance based on the xml passed
*
* @param string $documentXml
* @param null|string $stylesXml
* @return \PhpOffice\PhpWord\PhpWord
*/
protected function getDocumentFromString(array $partXmls = array())
{
$file = __DIR__ . '/../_files/temp.docx';
$zip = new \ZipArchive();
$zip->open($file, \ZipArchive::CREATE);
foreach ($this->parts as $partName => $part) {
if (array_key_exists($partName, $partXmls)) {
$zip->addFromString("{$partName}.xml", str_replace('{toReplace}', $partXmls[$partName], $this->parts[$partName]['xml']));
}
}
$zip->close();
$phpWord = new PhpWord();
foreach ($this->parts as $partName => $part) {
if (array_key_exists($partName, $partXmls)) {
$className = $this->parts[$partName]['class'];
$reader = new $className($file, "{$partName}.xml");
$reader->read($phpWord);
}
}
unlink($file);
return $phpWord;
}
}