tourze/symfony-temp-file-bundle
Composer 安装命令:
composer require tourze/symfony-temp-file-bundle
包简介
Symfony临时文件集中管理与自动清理bundle
README 文档
README
Introduction
symfony-temp-file-bundle is a Symfony bundle for centralized management and automatic cleanup of temporary files.
It ensures that temporary files generated during HTTP requests or console commands are automatically deleted at the end of the process,
reducing the risk of leftover temp files.
Features
- Unified temporary file management: Centralized creation and deletion of temporary files
- Automatic cleanup: Files are automatically deleted at the end of HTTP requests and console commands
- Multiple event listeners: Supports
KernelEvents::TERMINATE,KernelEvents::EXCEPTION,ConsoleEvents::TERMINATE,ConsoleEvents::ERROR - Simple API: Easy-to-use methods for generating and managing temporary files
- Zero configuration: Works out of the box with minimal setup
- Memory efficient: Uses array shifting to manage file cleanup
Installation
Requirements
- PHP >= 8.1
- Symfony >= 6.4
Composer
composer require tourze/symfony-temp-file-bundle
Manual Registration (Symfony Flex will register automatically in most cases)
Add to config/bundles.php:
Tourze\TempFileBundle\TempFileBundle::class => ['all' => true],
Quick Start
Generate a Temporary File
use Tourze\TempFileBundle\Service\TemporaryFileService; // Inject TemporaryFileService $tempFile = $temporaryFileService->generateTemporaryFileName('prefix_', 'txt'); file_put_contents($tempFile, 'hello world'); // The temp file will be automatically deleted at the end of the request or command
Register an Existing Temp File for Auto-Cleanup
// Register an existing file for automatic cleanup $temporaryFileService->addTemporaryFile($filePath);
Generate Temporary File Without Extension
// Generate temporary file without extension $tempFile = $temporaryFileService->generateTemporaryFileName('data_'); // Will create a file like: /tmp/data_abc123
API Documentation
TemporaryFileService
Methods
-
generateTemporaryFileName(string $prefix, ?string $ext = null): string- Generate a temporary file name with optional extension
- The file is automatically registered for cleanup
- Returns the full path to the temporary file
-
addTemporaryFile(string $file): void- Register an existing file for automatic cleanup
- Useful for files created outside the service
-
reset(): void- Manually clear the temporary file list
- Usually called automatically by event listeners
Event Listeners
The service automatically cleans up temporary files on these events:
KernelEvents::TERMINATE- Normal HTTP request terminationKernelEvents::EXCEPTION- HTTP request exceptionConsoleEvents::TERMINATE- Console command terminationConsoleEvents::ERROR- Console command error
Configuration
No configuration is required. The service is automatically registered and configured when the bundle is installed.
Contributing
- Issues and PRs are welcome
- Follow PSR-12 coding style
- Please ensure all PHPUnit tests pass before submitting
License
MIT License © tourze
Changelog
See [CHANGELOG.md] or Git commit history for details.
tourze/symfony-temp-file-bundle 适用场景与选型建议
tourze/symfony-temp-file-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.04k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/symfony-temp-file-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/symfony-temp-file-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-23