tourze / symfony-aop-doctrine-bundle
Doctrine enhance
Installs: 748
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^3.7.0 || ^4.0
- doctrine/doctrine-bundle: ^2.13
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/symfony-aop-bundle: ~0.0.4
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-11 17:47:35 UTC
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
See CONTRIBUTING.md for details.
License
MIT License. See LICENSE for details.
Changelog
See CHANGELOG.md for version history and upgrade notes.