Download the PHP package tourze/symfony-aop-coroutine-bundle without Composer
On this page you can find all versions of the php package tourze/symfony-aop-coroutine-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/symfony-aop-coroutine-bundle
More information about tourze/symfony-aop-coroutine-bundle
Files in tourze/symfony-aop-coroutine-bundle
Package symfony-aop-coroutine-bundle
Short Description Symfony AOP 协程支持,为服务实例提供协程隔离和上下文管理
License MIT
Informations about the package symfony-aop-coroutine-bundle
Symfony AOP Coroutine Bundle
中文
A Symfony bundle that provides coroutine-based service isolation using AOP (Aspect-Oriented Programming), enabling each request context to have its own independent service instances for better state isolation and concurrent processing.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Basic Usage
- Built-in Coroutine Services
- Request & Routing Services
- Template Engine
- Security Services
- Logging Services
- Other Services
- Advanced Configuration
- Alternative Ways to Enable Coroutine
- Enhanced Logging
- Important Notes
- How It Works
- Testing
- Contributing
- Development Setup
- License
- Changelog
Features
- AOP-based service isolation: Uses Aspect-Oriented Programming to intercept service calls and provide isolated instances
- Simple annotation-based configuration: Mark services as coroutine-enabled with the
#[AsCoroutine]attribute - Built-in support for common services: Automatic coroutine support for request_stack, twig, monolog, Doctrine EntityManager, session handlers, and more
- Automatic context management: Handles context creation and cleanup for each request lifecycle
- Enhanced logging: Automatically adds coroutine context ID to all log records for better traceability
- Memory efficient: Only creates isolated instances when needed, with automatic cleanup
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
tourze/symfony-aop-bundlefor AOP functionalitytourze/symfony-runtime-context-bundlefor context management
Installation
Install via Composer:
Register the bundle in config/bundles.php:
Quick Start
Basic Usage
-
Mark your service as coroutine-enabled using the
#[AsCoroutine]attribute: - Use the service in your controller - each request will have its own isolated state:
Built-in Coroutine Services
The following services are automatically coroutine-enabled by default:
Request & Routing Services
request_stack- Symfony's request stacksession_listener- Session event listenerrouter_listener- Router event listener
Template Engine
twig- Twig template enginetwig.loader.native_filesystem- Twig filesystem loader
Security Services
security.untracked_token_storage- Security token storagesecurity.csrf.token_storage- CSRF token storage
Logging Services
monolog.logger- Main Monolog loggermonolog.logger.*- All named Monolog loggers
Other Services
debug.stopwatch- Symfony debug stopwatch- All services implementing
SessionHandlerInterface - All services implementing
SessionUpdateTimestampHandlerInterface - All services implementing
Doctrine\ORM\EntityManagerInterface - Services tagged with
as-coroutine
Advanced Configuration
Alternative Ways to Enable Coroutine
Besides the #[AsCoroutine] attribute, you can also enable coroutine for services through:
-
Service Tags - Tag your service with
as-coroutine: - Interface Implementation - Services implementing these interfaces are automatically coroutine-enabled:
SessionHandlerInterfaceSessionUpdateTimestampHandlerInterfaceDoctrine\ORM\EntityManagerInterface
Enhanced Logging
The bundle automatically enhances logging by adding a context_id field to all log records, making it easier to trace requests across coroutine contexts:
Important Notes
- Memory Usage: Coroutine services consume more memory as each context maintains separate instances. Only use for services that require state isolation.
- Method Limitations: Methods returning
staticare not supported due to proxy limitations. - Dependency Management: Avoid circular dependencies in coroutine services.
- Singleton Services: Not recommended for services that should maintain global state.
How It Works
The bundle uses AOP (Aspect-Oriented Programming) to intercept service instantiation and method calls. When a coroutine-enabled service is accessed:
- The
CoroutineAspectintercepts the service call - It checks if an instance exists for the current context
- If not, it creates a new isolated instance using the
InstanceService - The instance is stored per context and automatically cleaned up when the request terminates
Testing
Run the test suite to ensure everything is working correctly:
Contributing
We welcome contributions! Please follow these guidelines:
- Submit Issues for bugs, feature requests, or questions
- Create Pull Requests with your improvements
- Follow PSR standards for code style and formatting
- Run tests before submitting PRs to ensure compatibility
- Update documentation if your changes affect usage
Development Setup
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author: tourze team
Changelog
See the Git commit history for version updates and important changes.
All versions of symfony-aop-coroutine-bundle with dependencies
doctrine/orm Version ^3.0
monolog/monolog Version ^3.1
symfony/config Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-kernel Version ^7.3
symfony/property-access Version ^7.3
symfony/routing Version ^7.3
symfony/service-contracts Version ^3.6
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/symfony-aop-bundle Version 1.0.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-runtime-context-bundle Version 1.0.*