Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Transaction Manager Bundle Laravel Package

aeatech/transaction-manager-bundle

Symfony bundle integrating AEATech Transaction Manager with support for multiple managers per connection, Doctrine DBAL adapter, MySQL/PostgreSQL transaction factories, configurable retry policies (backoff/jitter), attribute-based autoconfiguration, and lazy-loaded managers via service locator.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install the Bundle

    composer require aeatech/transaction-manager-bundle aeatech/transaction-manager-doctrine-adapter
    

    Ensure aeatech/transaction-manager-doctrine-adapter is included for Doctrine DBAL support.

  2. Enable the Bundle Add to config/bundles.php:

    return [
        // ...
        AeaTech\TransactionManagerBundle\AeaTechTransactionManagerBundle::class => ['all' => true],
    ];
    
  3. Configure Basic Setup Define a transaction manager in config/packages/aeatech_transaction_manager.yaml:

    aeatech_transaction_manager:
        managers:
            default:
                connection: default
                adapter: doctrine_dbal
                retry_policy: exponential_backoff
    
  4. First Use Case: Wrap a Repository Call

    use AeaTech\TransactionManager\TransactionManagerInterface;
    
    class SomeService {
        public function __construct(
            private TransactionManagerInterface $transactionManager
        ) {}
    
        public function updateUserData(): void {
            $this->transactionManager->execute(function () {
                // Your DB operations here (e.g., via Doctrine EntityManager)
                $entityManager->persist($user);
                $entityManager->flush();
            });
        }
    }
    

Implementation Patterns

Core Workflows

  1. Transaction Isolation Use named managers for different database connections (e.g., default, replica):

    aeatech_transaction_manager:
        managers:
            primary:
                connection: default
                adapter: doctrine_dbal
            read_only:
                connection: read_replica
                adapter: doctrine_dbal
                read_only: true
    

    Access via:

    $this->transactionManager->getManager('primary')->execute(...);
    
  2. Retry Policies Customize retry behavior in config:

    retry_policy:
        type: exponential_backoff
        max_attempts: 5
        initial_interval: 100 # ms
        multiplier: 2
        jitter: true
    

    Override globally or per-manager.

  3. Attribute-Based Autoconfiguration Annotate services for automatic classification (e.g., for retry logic):

    #[TransactionManager\ClassifyAsRetryable]
    class PaymentService { ... }
    
  4. Lazy-Loaded Managers Managers are initialized only when first accessed, reducing boot time:

    $manager = $this->transactionManager->getManager('lazy_manager');
    

Integration Tips

  • Doctrine EntityManager Integration Pass the EntityManager to the transaction block:

    $this->transactionManager->execute(function (EntityManager $em) {
        $em->createQuery(...)->execute();
    });
    
  • Symfony Messenger Integration Use the TransactionManagerInterface as a middleware for async messages:

    #[AsMessageHandler]
    public function __invoke(PaymentMessage $message, TransactionManagerInterface $tm) {
        $tm->execute(fn() => $this->processPayment($message));
    }
    
  • Event Listeners Attach listeners to transaction lifecycle events:

    $transactionManager->getManager('default')->addListener(
        TransactionEvent::PRE_COMMIT,
        fn(TransactionEvent $event) => $this->logTransactionStart($event)
    );
    

Gotchas and Tips

Pitfalls

  1. Connection Mismatch Errors Ensure the connection key in config matches your Doctrine DBAL connection names (e.g., default, read_replica). Verify with:

    $this->connection->getDatabasePlatform()->getName();
    
  2. Attribute Autoconfiguration Overrides PHP attributes (e.g., @ClassifyAsRetryable) may conflict with explicit config. Precedence:

    • Explicit config > Attributes > Defaults.
  3. Lazy Loading Pitfalls Managers are not initialized until first access. Avoid circular dependencies where a service expects a manager to be pre-configured.

  4. Retry Policy Misconfigurations Exponential backoff with jitter: true may cause unexpected delays. Test with:

    retry_policy:
        type: fixed_interval
        interval: 500 # ms (for testing)
    

Debugging

  • Enable Verbose Logging Add to config/packages/monolog.yaml:

    handlers:
        transaction:
            type: stream
            path: "%kernel.logs_dir%/transaction.log"
            level: debug
            channels: ["transaction"]
    

    Then configure the bundle to use the transaction channel.

  • Check Transaction State Use the TransactionManagerInterface to inspect active transactions:

    $transaction = $this->transactionManager->getCurrentTransaction();
    var_dump($transaction->isActive());
    

Extension Points

  1. Custom Adapters Implement AeaTech\TransactionManager\Adapter\AdapterInterface for non-Doctrine DBAL connections (e.g., Redis, Elasticsearch).

  2. Dynamic Manager Creation Extend the TransactionManagerRegistry to create managers on-the-fly:

    $registry->setManagerFactory('dynamic', fn() => new CustomManager());
    
  3. Custom Event Handlers Extend TransactionEvent or create subclasses for domain-specific events:

    class PaymentTransactionEvent extends TransactionEvent { ... }
    
  4. Override Default Factories Replace the default factory for a connection type (e.g., MySQL) in config:

    factories:
        mysql: App\Custom\MySqlTransactionFactory
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity