setPhpPresentation($pPhpPresentation ?? new PhpPresentation()); // Set up disk caching location $this->diskCachingDir = './'; // Set HashTable variables $this->oDrawingHashTable = new HashTable(); $this->setZipAdapter(new ZipArchiveAdapter()); } /** * Save PhpPresentation to file. * * @throws FileCopyException * @throws FileRemoveException * @throws InvalidParameterException */ public function save(string $pFilename): void { if (empty($pFilename)) { throw new InvalidParameterException('pFilename', ''); } $oPresentation = $this->getPhpPresentation(); // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if ('php://output' == \strtolower($pFilename) || 'php://stdout' == \strtolower($pFilename)) { $pFilename = @\tempnam('./', 'phppttmp'); if ('' == $pFilename) { $pFilename = $originalFilename; } } // Create drawing dictionary $this->getDrawingHashTable()->addFromSource($this->allDrawings()); $oZip = $this->getZipAdapter(); $oZip->open($pFilename); $oDir = new \DirectoryIterator(\dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PowerPoint2007'); $arrayFiles = []; foreach ($oDir as $oFile) { if (!$oFile->isFile()) { continue; } $class = __NAMESPACE__ . '\\PowerPoint2007\\' . $oFile->getBasename('.php'); $class = new \ReflectionClass($class); if ($class->isAbstract() || !$class->isSubclassOf(AbstractDecoratorWriter::class)) { continue; } $arrayFiles[$oFile->getBasename('.php')] = $class; } \ksort($arrayFiles); foreach ($arrayFiles as $o) { $oService = $o->newInstance(); $oService->setZip($oZip); $oService->setPresentation($oPresentation); $oService->setDrawingHashTable($this->getDrawingHashTable()); $oZip = $oService->render(); unset($oService); } // Close file $oZip->close(); // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { if (false === \copy($pFilename, $originalFilename)) { throw new FileCopyException($pFilename, $originalFilename); } if (false === @\unlink($pFilename)) { throw new FileRemoveException($pFilename); } } } /** * Get use disk caching where possible? * * @return bool */ public function hasDiskCaching() { return $this->useDiskCaching; } /** * Set use disk caching where possible? * * @param bool $useDiskCaching * @param string $directory Disk caching directory * * @throws DirectoryNotFoundException * * @return \PhpOffice\PhpPresentation\Writer\PowerPoint2007 */ public function setUseDiskCaching(bool $useDiskCaching = false, string $directory = null) { $this->useDiskCaching = $useDiskCaching; if (!\is_null($directory)) { if (!\is_dir($directory)) { throw new DirectoryNotFoundException($directory); } $this->diskCachingDir = $directory; } return $this; } /** * Get disk caching directory. * * @return string */ public function getDiskCachingDirectory() { return $this->diskCachingDir; } }