tourze / symfony-runtime-context-bundle
Symfony 上下文管理和延迟执行模块
Installs: 11 685
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/symfony-runtime-context-bundle
Requires
- php: ^8.1
- psr/log: ^3|^2|^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-kernel: ^6.4
- symfony/service-contracts: ^3.5
- symfony/yaml: ^6.4 || ^7.1
- tourze/backtrace-helper: 0.1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
Context management module for Symfony applications, supporting deferred task execution and unique context identification.
Features
- Obtain a unique ID for the current runtime context
- Support for deferred (defer) task execution
- Reset mechanism compatible with Symfony lifecycle
- Extensible for different contexts (e.g., FPM, CLI)
Installation
- Requires PHP 8.1+
- Requires Symfony 6.4+ core components
- Install via Composer:
composer require tourze/symfony-runtime-context-bundle
Quick Start
- 
Register the bundle in config/bundles.php:return [ Tourze\Symfony\RuntimeContextBundle\RuntimeContextBundle::class => ['all' => true], ]; 
- 
Inject and use ContextServiceInterface:use Tourze\Symfony\RuntimeContextBundle\Service\ContextServiceInterface; public function index(ContextServiceInterface $contextService) { $id = $contextService->getId(); $contextService->defer(function () { // Deferred task }); } 
Documentation
- ContextServiceInterface: Defines the core context service interface, including unique ID retrieval, deferred execution, and coroutine support
- DefaultContextService: Default implementation based on process ID or generated unique ID
- DeferCallSubscriber: Event subscriber responsible for executing all deferred tasks at the end of the lifecycle
Contributing
- Issues and PRs are welcome
- Follow PSR-12 code style
- Please ensure PHPUnit tests pass before submitting
License
- MIT License
- (c) tourze
Changelog
- See CHANGELOG.md or commit history for details