tourze / symfony-temp-file-bundle
临时文件管理
Installs: 131
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/service-contracts: ^3
- symfony/yaml: ^6.4 || ^7.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-23 20:23:44 UTC
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 management of temporary file creation and deletion
- Automatic cleanup at the end of HTTP requests and console commands
- Simple and easy-to-use API
- Seamless integration, minimal configuration required
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
$temporaryFileService->addTemporaryFile($filePath);
Documentation
- All generated or registered temp files are automatically cleaned up at the end of HTTP requests or console commands.
- Listens to multiple events:
KernelEvents::TERMINATE
,KernelEvents::EXCEPTION
,ConsoleEvents::TERMINATE
,ConsoleEvents::ERROR
. - No manual cleanup required, greatly reduces resource leakage risk.
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.