Download the PHP package glucnac/ziparchivemanager without Composer
On this page you can find all versions of the php package glucnac/ziparchivemanager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download glucnac/ziparchivemanager
More information about glucnac/ziparchivemanager
Files in glucnac/ziparchivemanager
Package ziparchivemanager
Short Description A simple wrapper around PHP's ZipArchive class that provides a more object-oriented interface to make it easier to create, extract, and modify zip archives.
License MIT
Homepage https://github.com/GlucNAc/ZipArchiveManager
Informations about the package ziparchivemanager
GlucNAc/ZipArchiveManager
A simple wrapper around PHP's native ZipArchive, to make it easier to work with.
Installation
Install this package as a dependency using Composer.
Usage
The GlucNAc/ZipArchiveManager provides a more object-oriented interface to work with PHP's native ZipArchive, making it easier to create, extract, and modify zip archives.
Creating a new ZipArchive
To create a new zip archive, you can use the ZipArchiveBuilder
class. The ZipArchiveBuilder
requires a ZipArchiveManager
object to manage the storage of the archive. The ZipArchiveBuilder
class provides a fluent interface to add files to the archive.
Now the archive exists at /path/to/storage/archive/test.zip
and will have this structure:
This can also be done quickly with the ZipArchiveBuilder::buildWithFiles
method:
Customizing the file structure in the archive
By default, the archive structure will mirror the structure of the files. If you want to change the structure of the files in the archive, you can use an associative array where the keys are the paths to the files and the values are the paths to the files in the archive:
Now the archive exists at /path/to/storage/archive/test.zip
and will have this structure:
Adding files from a directory
Given the following directory structure:
If you want to create an archive with all the files in the /path/to
directory, while keeping the structure of the files in the archive, you can use the ZipArchiveBuilder::addFilesFromPath
method:
The ArchivableFileManager::getArchivableFilesFromPath
method returns an array of ArchivableFile
objects, which implement the ArchivableFileInterface
interface, and where the path of the files in the archive will be relative to the path passed to the method (/path/to
in this case).
This works because ZipArchiveBuilder::buildWithFiles
, ZipArchiveBuilder::addFiles
and ZipArchiveBuilder::addFile
methods also accept an array of ArchivableFileInterface
objects (in addition to file paths).
See the ArchivableFile section for more information about ArchivableFileInterface
and ArchivableFile
objects.
Keeping the archive open
By default, build
methods will close the archive after building it. If you want to keep the archive open, you can pass false
as the first argument to the build
method:
Adding files to an existing zip archive
To add files to an existing zip archive, you just have to open the archive with the ZipArchiveManager::open
method
and use methods described in the Creating a new ZipArchive section:
Extracting files from a ZipArchive
To extract files from a zip archive, simply use the ZipArchiveManager::extractFiles
method:
ArchivableFile
For this section, let's consider the following directory structure:
You may have noticed that ZipArchiveManager
uses the ArchivableFile
class to represent files that can be added to a zip archive. More precisely, ZipArchiveManager
expects an object that implements the ArchivableFileInterface. This interface defines the methods that an object must implement to be considered an archivable file. The ArchivableFile
class provided by this package implements this interface and provides a simple way to work with files that can be added to a zip archive.
You can create your own class that implements this interface, or you can use the ArchivableFile
class provided by this package. To do so, you can use the ArchivableFileManager::getArchivableFileFromPath
method to get an ArchivableFile
object from a file path:
You can also use the ArchivableFileManager::getArchivableFilesFromPath
method to get an array of ArchivableFile
objects from a directory path:
Internally, the ArchivableFile
class uses the SplFileInfo
class to represent files. You can also use the SplFileInfoToArchivableFileTransformer
class to transform an SplFileInfo
object into an ArchivableFile
object:
Contributing
Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.
Coordinated Disclosure
Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read SECURITY.md for instructions on submitting a vulnerability report.
Copyright and License
GlucNAc/ZipArchiveManager is copyright © GlucNAc and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.
All versions of ziparchivemanager with dependencies
ext-zip Version *
doctrine/collections Version ^2.0|^3.0
symfony/finder Version ^5.4|^6.0|^7.0
symfony/options-resolver Version ^5.4|^6.0|^7.0