tourze/symfony-aop-doctrine-bundle
最新稳定版本:1.0.1
Composer 安装命令:
composer require tourze/symfony-aop-doctrine-bundle
包简介
Doctrine enhance
README 文档
README
A Symfony bundle that enhances Doctrine ORM with declarative transaction management via AOP (Aspect-Oriented Programming), inspired by the design of Spring Boot.
Features
- Declarative transaction support with
#[Transactional]attribute - Automatic transaction begin/commit/rollback
- Nested transaction and transaction propagation
- Detailed transaction logging
- Smart transaction reuse and performance optimization
Installation
composer require tourze/symfony-aop-doctrine-bundle
Quick Start
use Tourze\Symfony\AopDoctrineBundle\Attribute\Transactional; class YourService { #[Transactional] public function doSomething() { $this->entityManager->persist($entity); $this->entityManager->flush(); // If an exception is thrown, the transaction will be rolled back automatically. // If completed normally, the transaction will be committed automatically. } }
Nested Transactions
class YourService { #[Transactional] public function outerMethod() { $this->innerMethod(); // The transaction is committed here. } #[Transactional] public function innerMethod() { // This method reuses the outer transaction, no new transaction is created. } }
Transaction Logging
use Psr\Log\LoggerInterface; class YourService { public function __construct(private LoggerInterface $logger) {} #[Transactional] public function doSomething() { // Transaction start and end will be automatically logged. $this->entityManager->persist($entity); $this->entityManager->flush(); } }
Notes
- The
#[Transactional]attribute can only be applied to public methods. - Nested transactions are automatically reused.
- Any exception thrown in a transactional method will cause a rollback.
- Make sure to use the correct EntityManager inside transactional methods.
- Avoid long-running transactions and non-DB operations inside transactions.
- Distributed and cross-database transactions are not supported.
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-08