定制 imponeer/archive-download-builder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imponeer/archive-download-builder

Composer 安装命令:

composer require imponeer/archive-download-builder

包简介

A PHP library for building and downloading archive files (ZIP and TAR.GZ) with optional Flysystem support for various file sources

README 文档

README

PHP Version License Latest Release Downloads

A PHP library for building and downloading archive files (ZIP and TAR.GZ) with support for various file sources through the Flysystem abstraction layer.

This library is a modern rewrite of the XOOPS downloader classes (Downloader, ZipDownloader, TarDownloader) with MIT license compatibility and modern PHP coding standards.

Installation

Install via Composer:

composer require imponeer/archive-download-builder

Examples

Simple ZIP Archive (using default filesystem)

<?php

use Imponeer\ArchiveDownloadBuilder\ZipDownloader;

// Create ZIP downloader (uses entire filesystem as base when no filesystem is specified)
$downloader = new ZipDownloader();

// Add files from anywhere on the filesystem
$downloader->addFile('/path/to/document.pdf');
$downloader->addFile('/home/user/image.jpg', 'renamed-image.jpg');

// Add file data directly
$downloader->addFileData('Hello World!', 'hello.txt');

// Generate and download
$downloader->download('my-archive');

ZIP Archive with Custom Filesystem

<?php

use Imponeer\ArchiveDownloadBuilder\ZipDownloader;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

// Create filesystem adapter for a specific directory
$filesystem = new Filesystem(new LocalFilesystemAdapter('/path/to/files'));

// Create ZIP downloader with custom filesystem
$downloader = new ZipDownloader(filesystem: $filesystem);

// Add files to archive (paths are relative to the filesystem adapter)
$downloader->addFile('document.pdf');
$downloader->addFile('image.jpg', 'renamed-image.jpg');

// Add file data directly
$downloader->addFileData('Hello World!', 'hello.txt');

// Generate and download
$downloader->download('my-archive');

Basic TAR.GZ Archive

<?php

use Imponeer\ArchiveDownloadBuilder\TarDownloader;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

// Create filesystem adapter
$filesystem = new Filesystem(new LocalFilesystemAdapter('/path/to/files'));

// Create TAR downloader
$downloader = new TarDownloader(filesystem: $filesystem);

// Add files to archive
$downloader->addFile('config.json');
$downloader->addBinaryFile('data.bin', 'backup-data.bin');

// Generate and download
$downloader->download('backup');

Custom MIME Types and Extensions

// Custom ZIP configuration
$zipDownloader = new ZipDownloader(
    ext: '.custom.zip',
    mimetype: 'application/custom-zip',
    filesystem: $filesystem
);

// Custom TAR configuration
$tarDownloader = new TarDownloader(
    ext: '.backup.tar.gz',
    mimetype: 'application/x-compressed-tar',
    filesystem: $filesystem,
    tmpPath: '/custom/temp/path'
);

Working with Different Filesystems

use League\Flysystem\Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use League\Flysystem\Ftp\FtpAdapter;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;

// In-memory filesystem
$memoryFs = new Filesystem(new InMemoryFilesystemAdapter());
$downloader = new ZipDownloader(filesystem: $memoryFs);

// FTP filesystem
$ftpFs = new Filesystem(new FtpAdapter($ftpConfig));
$downloader = new ZipDownloader(filesystem: $ftpFs);

// AWS S3 filesystem
$s3Fs = new Filesystem(new AwsS3V3Adapter($s3Client, $bucket));
$downloader = new ZipDownloader(filesystem: $s3Fs);

PSR-7 Response Integration

// Get PSR-7 response instead of direct download
$response = $downloader->toResponse('archive-name');

// Use with your favorite HTTP framework
// Symfony
return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());

// Laravel
return response($response->getBody(), $response->getStatusCode(), $response->getHeaders());

// Slim Framework
return $response; // Direct usage

Bulk File Operations

use League\Flysystem\FileAttributes;

// Add all files from a directory
foreach ($filesystem->listContents('/documents', true) as $item) {
    if ($item instanceof FileAttributes) {
        $downloader->addFile($item->path());
    }
}

// Add files with custom naming pattern
$files = ['report1.pdf', 'report2.pdf', 'summary.doc'];
foreach ($files as $index => $file) {
    $downloader->addFile($file, sprintf('report_%02d_%s', $index + 1, basename($file)));
}

Error Handling

use PhpZip\Exception\ZipException;
use League\Flysystem\FilesystemException;

try {
    $downloader = new ZipDownloader(filesystem: $filesystem);
    $downloader->addFile('nonexistent-file.txt');
    $downloader->download('archive');
} catch (FilesystemException $e) {
    // Handle filesystem errors (file not found, permission issues, etc.)
    echo "Filesystem error: " . $e->getMessage();
} catch (ZipException $e) {
    // Handle ZIP-specific errors
    echo "ZIP error: " . $e->getMessage();
}

Documentation

API documentation is automatically generated and available in the project's wiki. For more detailed information about the classes and methods, please refer to the project wiki.

Development

Running Tests

composer test

Code Quality

# PHP CodeSniffer
composer phpcs

# Fix coding standards
composer phpcbf

# Static analysis
composer phpstan

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure your code follows PSR-12 standards and includes appropriate tests.

Support

For issues and questions, please use the GitHub Issues page.

imponeer/archive-download-builder 适用场景与选型建议

imponeer/archive-download-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 imponeer/archive-download-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 imponeer/archive-download-builder 我们能提供哪些服务?
定制开发 / 二次开发

基于 imponeer/archive-download-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-03