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