victor78/yii2-zipper
Composer 安装命令:
composer require victor78/yii2-zipper
包简介
Yii2-Zipper is archiving component for Yii2.
README 文档
README
Archiving extension for Yii2 Framework - zip, tar, tar.gz, tar.bz2, 7zip (for zip archive with supporting passwords). It's a shell over ZippyExt.
Расширение для архивации в Yii2 Framework - в виде zip, tar, tar.gz, tar.bz2, 7zip (только для zip архива - в том числе с поддержкой паролей).
English:
Русский:
Requirements
- PHP >= 8.1
- Yii2 framework
- ZippyExt
^1.0 - For
ziptype — thezipconsole utility or the PHPzipextension. - For
tar,tar.gz,tar.bz2— GNU tar or BSD tar. - For
7zip— the7zaor7zbinary available inPATH.
PHP Compatibility
| yii2-zipper | zippy-ext | PHP |
|---|---|---|
| 1.x | ^1.0 | 8.1–8.3 |
| 0.x | ~0.0.4 | 7.0+ |
Installation
The preferred way to install this extension is through composer.
Either run
composer require victor78/yii2-zipper:"^1.0"
or add
"victor78/yii2-zipper": "^1.0"
to the require section of your composer.json.
Configuration
'type' and 'password' are optional.
return [ //.... 'components' => [ 'zipper' => [ 'class' => 'Victor78\Zipper\Zipper', //required 'type' => '7zip', //or 'zip' (default), 'tar', 'tar.gz', 'tar.bz2' 'password' => 'password12345', //optional, only for 7zip type ], ] ];
How to use
To create archive:
//files to archive $files = [ '/path/to/file1', '/path/to/file2', ]; //to create tar archive $tarArchive = Yii::$app->zipper->create('/tmp/archive.tar', $files, true, 'tar'); //to create zip archive by 7zip with password $sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, '7zip', 'password12345'); //or, if you've configured zipper component like in the example above: $sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files); $zipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, 'zip');
To open archive and extract:
$zipArchive = Yii::$app->zipper->open('/tmp/archive.zip', 'zip'); $tarArchive = Yii::$app->zipper->open('/tmp/archive.tar', 'tar'); $sevenZipArchive = Yii::$app->zipper->open('/tmp/archive.zip', '7zip'); //open 7zip with password $sevenZipArchiveEncrypted = Yii::$app->zipper->open('/tmp/archive.zip', '7zip', 'password12345'); $zipArchive->extract('/tmp/extracted/');
When you configure zipper component with optional properties 'type' and 'password', they will be used as default fourth and fifth parameters in the create method, and as default second and third parameters in the open method. If you use these parameters in the methods explicitly, they will overwrite the properties from the config. You can leave out the properties in the config and the parameters in the methods entirely - in this case Zipper will try to understand which adapter to use, but it doesn't work with a 7zip archive.
Both methods return an Archive object. You can find the details about how to use this object and other information in the documentation of the ZippyExt library.
Установка
Предпочтительным способом установки является при помощи composer.
Либо командой из консоли
composer require victor78/yii2-zipper:"^1.0"
либо включением в composer.json в секцию require.
"victor78/yii2-zipper": "^1.0"
Настройка
'type' и 'password' - опциональны.
return [ //.... 'components' => [ 'zipper' => [ 'class' => 'Victor78\Zipper\Zipper', //required 'type' => '7zip', //или: 'zip' (по умолчанию), 'tar', 'tar.gz', 'tar.bz2' 'password' => 'password12345', //опционально, работает только при типе 7zip ], ] ];
Как использовать
Для создания архива:
//files to archive $files = [ '/path/to/file1', '/path/to/file2', ]; //создать tar архив $tarArchive = Yii::$app->zipper->create('/tmp/archive.tar', $files, true, 'tar'); //создать zip архив с паролем при помощи 7zip $sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, '7zip', 'password12345'); //или, если вы настроили компонент Zipper как в примере выше: $sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files); $zipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, 'zip');
Открыть и распаковать архив:
$zipArchive = Yii::$app->zipper->open('/tmp/archive.zip', 'zip'); $tarArchive = Yii::$app->zipper->open('/tmp/archive.tar', 'tar'); $sevenZipArchive = Yii::$app->zipper->open('/tmp/archive.zip', '7zip'); //открыть запароленный zip созданный при помощи 7zip $sevenZipArchiveEncrypted = Yii::$app->zipper->open('/tmp/archive.zip', '7zip', 'password12345'); $zipArchive->extract('/tmp/extracted/');
Если вы настроили компонент Zipper с опциональными свойствами 'type' и 'password', они будут использованы как дефолтные четвёртый и пятый параметры в методе create и второй и третий параметры в методе open. Если эти параметры в этих методах указываются явно, то они переписывают свойства из конфига. Вы можете опустить свойства из конфига и параметры в методах вообще - в таком случае Zipper попытается самостоятельно понять какой именно адаптер какого архиватора использовать, но это точно не будет работать в случае zip архива, созданного при помощи 7zip.
Оба метода возвращают объект Archive. Вы можете найти детали о том, как использовать данный объект и другую информацию в документации к библиотеке ZippyExt.
Требования
- PHP >= 8.1, фреймворк Yii2 и пакет ZippyExt
^1.0. - Для архивирования в чистый zip используется утилита zip или расширение PHP для zip, так что или утилита, или расширение должны быть установлены на сервере для упаковки и распаковки zip.
- Для tar, tar.gz, tar.bz2 Zipper пытается использовать GNU tar или BSD tar, один из них должен быть установлен на сервере для этих типов архивов.
- Для упаковки/распаковки zip при помощи 7zip, на сервере должна быть установлена утилита
7zaили7z.
victor78/yii2-zipper 适用场景与选型建议
victor78/yii2-zipper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.76k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「component」 「zip」 「archive」 「tar」 「yii2」 「zipper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 victor78/yii2-zipper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 victor78/yii2-zipper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 victor78/yii2-zipper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
FSi DataSource Component
Iteration tools for PHP
Priveate for SkeekS CMS
Convert and operate with FIPS codes for states, counties, etc.
A trait to make an Eloquent model archivable
统计信息
- 总下载量: 28.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 36
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-20