Ejemplo n.º 1
0
 /**
  * Get document content
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @param string $writerName
  * @return \PhpOffice\PhpWord\Tests\XmlDocument
  */
 public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007')
 {
     self::$file = tempnam(sys_get_temp_dir(), 'PhpWord');
     if (!is_dir(sys_get_temp_dir() . '/PhpWord_Unit_Test/')) {
         mkdir(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
     }
     $xmlWriter = IOFactory::createWriter($phpWord, $writerName);
     $xmlWriter->save(self::$file);
     $zip = new \ZipArchive();
     $res = $zip->open(self::$file);
     if ($res === true) {
         $zip->extractTo(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
         $zip->close();
     }
     return new XmlDocument(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
 }
Ejemplo n.º 2
0
 /**
  * Get document content
  *
  * @since 0.12.0 Throws CreateTemporaryFileException.
  *
  * @param \PhpOffice\PhpWord\PhpWord $phpWord
  * @param string $writerName
  *
  * @return \PhpOffice\PhpWord\Tests\XmlDocument
  *
  * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
  */
 public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007')
 {
     self::$file = tempnam(Settings::getTempDir(), 'PhpWord');
     if (false === self::$file) {
         throw new CreateTemporaryFileException();
     }
     if (!is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
         mkdir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
     }
     $xmlWriter = IOFactory::createWriter($phpWord, $writerName);
     $xmlWriter->save(self::$file);
     $zip = new \ZipArchive();
     $res = $zip->open(self::$file);
     if (true === $res) {
         $zip->extractTo(Settings::getTempDir() . '/PhpWord_Unit_Test/');
         $zip->close();
     }
     return new XmlDocument(Settings::getTempDir() . '/PhpWord_Unit_Test/');
 }