/** * @param AbstractArchiveBuilder $archiveBuilder * @return $this */ public function add(AbstractArchiveBuilder $archiveBuilder) { if ($archiveBuilder->isAvailable()) { $archiveBuilder->setEnvironment($this->environment); $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; } return $this; }
/** * @param string $environment * @return $this * * Sets the execution environment of the Kernel, * used to know which cache is used. */ public function setEnvironment($environment) { parent::setEnvironment($environment); $this->zip = new \ZipArchive(); $cacheFile = $this->generateCacheFile($environment); if (file_exists($cacheFile)) { unlink($cacheFile); } $opening = $this->zip->open($cacheFile, \ZipArchive::CREATE); if ($opening !== true) { throw new \ErrorException($this->translator->trans("An unknown error append")); } $this->cacheFile = $cacheFile; return $this; }
/** * @param DocumentsExportInterface $handler * @param AbstractArchiveBuilder $archiveBuilder * * Procedure that add documents in the export's archive */ protected function processExportDocuments(DocumentsExportInterface $handler, AbstractArchiveBuilder $archiveBuilder) { foreach ($handler->getDocumentsPaths() as $name => $documentPath) { $archiveBuilder->addFile($documentPath, $handler::DOCUMENTS_DIRECTORY, is_integer($name) ? null : $name); } }
public function getFileContentInArchive(AbstractArchiveBuilder $archiveBuilder, FormatterManager $formatterManager, array $types) { $content = null; /** * Check expected file names for each formatter */ $fileNames = []; /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */ foreach ($formatterManager->getFormattersByTypes($types) as $formatter) { $fileName = $formatter::FILENAME . "." . $formatter->getExtension(); $fileNames[] = $fileName; if ($archiveBuilder->hasFile($fileName)) { $content = $archiveBuilder->getFileContent($fileName); break; } } if ($content === null) { throw new FileNotFoundException($this->getTranslator()->trans("Your archive must contain one of these file and doesn't: %files", ["%files" => implode(", ", $fileNames)])); } return array("formatter" => $formatter, "content" => $content); }