zip = new \ZipArchive(); if ($this->zip->open($file_path, $configuration['flags'] ?? 0) !== TRUE) { throw new ArchiverException("Cannot open '$file_path'"); } } /** * {@inheritdoc} */ public function add($file_path) { $this->zip->addFile($file_path); return $this; } /** * {@inheritdoc} */ public function remove($file_path) { $this->zip->deleteName($file_path); return $this; } /** * {@inheritdoc} */ public function extract($path, array $files = []) { if ($files) { $this->zip->extractTo($path, $files); } else { $this->zip->extractTo($path); } return $this; } /** * {@inheritdoc} */ public function listContents() { $files = []; for ($i = 0; $i < $this->zip->numFiles; $i++) { $files[] = $this->zip->getNameIndex($i); } return $files; } /** * Retrieves the zip engine itself. * * In some cases it may be necessary to directly access the underlying * ZipArchive object for implementation-specific logic. This is for advanced * use only as it is not shared by other implementations of ArchiveInterface. * * @return \ZipArchive * The ZipArchive object used by this object. */ public function getArchive() { return $this->zip; } }