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

Doctrine Orm Bridge Laravel Package

dlakomski/doctrine-orm-bridge

Doctrine ORM bridge for SimpleBus/MessageBus. Provides command bus middlewares to wrap command handling in database transactions and to dispatch domain events generated by Doctrine entities. Links to main SimpleBus repo for issues and PRs.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven & CQRS Alignment: The package excels in Laravel applications leveraging CQRS (Command Query Responsibility Segregation) or event-driven architectures. It bridges Doctrine ORM (common in Laravel via doctrine/dbal or doctrine/orm) with SimpleBus MessageBus, enabling transactional command handling and domain event processing.
    • Example Use Case: A Laravel app using Laravel Echo/Pusher for real-time updates could integrate this to publish Doctrine entity events (e.g., UserCreatedEvent) to a message bus, decoupling event handling from the ORM layer.
  • Laravel Ecosystem Gaps: Laravel’s native queue system and events are tightly coupled to Symfony’s EventDispatcher. This package offers an alternative for teams already using SimpleBus (or considering it) to avoid reinventing transactional event handling.
  • Domain-Driven Design (DDD) Fit: Ideal for DDD-heavy Laravel apps where entities emit domain events (e.g., OrderShipped) that must be processed transactionally.

Integration Feasibility

  • Doctrine ORM Dependency: Requires Doctrine ORM (not DBAL alone), which may not be a default in Laravel. Teams using Eloquent would need to adopt Doctrine ORM, adding complexity.
  • SimpleBus Dependency: Mandates SimpleBus/MessageBus (v1.0+), which is not a Laravel-first package. Integration would require:
    • Configuring SimpleBus alongside Laravel’s queue system.
    • Potentially duplicating event handling (Laravel’s Event system vs. SimpleBus).
  • Middleware-Based: The package injects middlewares into the command bus, which aligns with Laravel’s middleware stack but requires familiarity with SimpleBus’s middleware pattern.

Technical Risk

  • Low-Moderate Risk:
    • Transaction Rollback Handling: The package fixes a critical issue (v3.0.0) where failed transactions would break the command bus. However, edge cases (e.g., nested transactions) may still require custom handling.
    • Event Deduplication: Events are erased post-processing (v2.0.1), which prevents reprocessing but may conflict with Laravel’s event replayability (e.g., testing).
    • Performance Overhead: Each command/event processed via the bridge incurs Doctrine ORM hydration and message bus serialization, adding latency compared to native Laravel queues.
  • High Risk:
    • Laravel-SimpleBus Conflict: Laravel’s queue workers and event listeners may clash with SimpleBus’s message handlers, leading to:
      • Duplicate event processing.
      • Inconsistent transaction boundaries (e.g., Laravel’s queue:work vs. SimpleBus’s middleware).
    • Maintenance Burden: The package is abandoned (last update: 2019) and lacks Laravel-specific documentation. Custom glue code may be needed to resolve:
      • Service container conflicts (Laravel’s DI vs. SimpleBus’s).
      • Queue driver compatibility (e.g., Redis, database).

Key Questions

  1. Why SimpleBus?
    • Does the team already use SimpleBus, or is this a greenfield adoption?
    • Could Laravel’s native queues/events suffice with custom middleware (e.g., wrapping dispatch() in a transaction)?
  2. ORM Strategy
    • Is Doctrine ORM a hard requirement, or is this a potential migration from Eloquent?
    • How would this interact with Laravel’s migrations, factories, and seeders?
  3. Event Handling
    • Are domain events idempotent? If not, how will deduplication (via this package) interact with Laravel’s event retries?
    • Will this replace or augment Laravel’s Event system?
  4. Failure Modes
    • How will failed transactions (e.g., deadlocks) be handled in a Laravel context (e.g., queue retries)?
    • What’s the fallback if the bridge fails (e.g., events not published)?
  5. Testing
    • How will unit/integration tests mock SimpleBus and Doctrine ORM without tight coupling to Laravel’s testing tools?

Integration Approach

Stack Fit

  • Compatible Stack:
    • Laravel 8/9/10 (with Doctrine ORM integration, e.g., spatie/laravel-doctrine-orm).
    • PHP 8.0+ (SimpleBus v1.0+ requires PHP 7.2+).
    • SimpleBus/MessageBus (v1.0+).
    • Doctrine ORM (v2.5+).
  • Incompatible Stack:
    • Eloquent-only apps: Requires Doctrine ORM adoption.
    • Symfony-based Laravel apps: May conflict with Symfony’s EventDispatcher.
    • Queue-heavy apps: SimpleBus’s middleware may introduce unnecessary complexity for simple command processing.

Migration Path

  1. Phase 1: Proof of Concept
    • Install Doctrine ORM (if not present) and SimpleBus/MessageBus.
    • Implement a single command (e.g., CreateUserCommand) with transactional handling via the bridge.
    • Verify event publishing (e.g., UserCreatedEvent) works alongside Laravel’s native events.
  2. Phase 2: Gradual Adoption
    • Replace critical transactional commands (e.g., payments, orders) with SimpleBus handlers.
    • Migrate domain events from Laravel’s Event system to SimpleBus, ensuring no duplicates.
    • Update queue workers to handle both Laravel jobs and SimpleBus messages.
  3. Phase 3: Full Integration
    • Replace Laravel’s event listeners with SimpleBus subscribers where applicable.
    • Customize the bridge for Laravel-specific needs (e.g., logging, metrics).

Compatibility

  • Doctrine ORM: Works seamlessly if already in use. Conflicts may arise with:
    • Laravel’s Model events (e.g., retrieved, saved) vs. Doctrine’s lifecycle callbacks.
    • EntityManager lifecycle (e.g., clearing, flushing) in Laravel’s request lifecycle.
  • SimpleBus: May conflict with:
    • Laravel’s service container (SimpleBus uses its own DI).
    • Queue drivers: SimpleBus assumes synchronous processing; Laravel’s queues are async.
  • Laravel-Specific:
    • Artisan commands: Can integrate SimpleBus commands via Laravel’s Artisan::call().
    • Horizon/Vue: SimpleBus messages won’t appear in Horizon’s dashboard; custom monitoring may be needed.

Sequencing

  1. Prerequisites:
    • Set up Doctrine ORM in Laravel (e.g., via spatie/laravel-doctrine-orm).
    • Configure SimpleBus as a Laravel service provider.
  2. Core Integration:
    • Register the bridge’s command bus middlewares in Laravel’s container.
    • Replace EntityManager usage in commands with the bridge’s transactional wrappers.
  3. Event Handling:
    • Configure Doctrine event listeners to publish events to SimpleBus.
    • Ensure event deduplication aligns with Laravel’s caching (e.g., Redis).
  4. Testing:
    • Mock SimpleBus in PHPUnit tests.
    • Test transaction rollbacks and event reprocessing.
  5. Deployment:
    • Monitor queue backlogs for SimpleBus messages.
    • Gradually increase load to identify bottlenecks (e.g., Doctrine hydration).

Operational Impact

Maintenance

  • Pros:
    • Decoupled event handling: Domain events are processed independently of HTTP requests.
    • Transaction safety: Commands fail atomically with database operations.
  • Cons:
    • Dual Event Systems: Managing both Laravel’s Event system and SimpleBus events adds complexity.
    • Abandoned Package: No active maintenance means:
      • Bug fixes must be backported.
      • Laravel version compatibility is untested.
    • Custom Glue Code: Likely needed for:
      • Laravel’s service container integration.
      • Queue worker coordination.
      • Logging/monitoring (e.g., OpenTelemetry traces).

Support

  • Debugging Challenges:
    • Stack Traces: SimpleBus errors may not integrate cleanly with Laravel’s exception handler.
    • Queue Dead Letters: Failed SimpleBus messages won’t appear in Laravel’s failed_jobs table.
  • Tooling Gaps:
    • Horizon: Won’t visualize SimpleBus messages.
    • Laravel Debugbar: May not show SimpleBus metrics.
  • Workarounds:
    • Custom Telescope channels for SimpleBus events.
    • Logging middleware to track message flow.

Scaling

  • Performance:
    • Doctrine ORM Overhead: Each command/event processed via the bridge incurs:
      • Entity hydration.
      • Message serialization/deserialization.
    • Queue Contention: SimpleBus’s synchronous processing may bottleneck Laravel’s async queues.
  • **Horizontal
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours