simple-bus/doctrine-orm-bridge
Doctrine ORM bridge for SimpleBus/MessageBus. Provides command bus middleware to run command handling inside Doctrine transactions and to dispatch domain events generated by entities. Part of the SimpleBus ecosystem.
PrePersist, PostUpdate), reducing boilerplate for side effects like notifications or analytics. This complements Laravel’s model observers but targets domain-level events rather than framework-level ones.Illuminate\Events and this package’s domain events could overlap. Clarify whether domain events (e.g., OrderCreated) should replace or coexist with Laravel’s model events (e.g., created).DB::transaction()) may conflict if not scoped properly.EntityManager fails mid-transaction, the bridge resets it, but this could mask deeper issues (e.g., connection pools).EntityManager and Connection for unit tests is non-trivial. Consider integration tests with a test database.HttpFoundation and EventDispatcher, already present in Laravel’s vendor tree.OrderCreated) that should trigger side effects.composer require simplebus/doctrine-orm-bridge simplebus/message-bus doctrine/orm
// app/Providers/SimpleBusServiceProvider.php
public function register()
{
$this->app->bind(\SimpleBus\MessageBus\MessageBus::class, function ($app) {
$entityManager = $app->make(\Doctrine\ORM\EntityManagerInterface::class);
$bus = new \SimpleBus\MessageBus\MessageBus(
new \SimpleBus\MessageBus\Middleware\MiddlewareStack(
new \SimpleBus\DoctrineORMBridge\Middleware\TransactionMiddleware($entityManager),
new \SimpleBus\DoctrineORMBridge\Middleware\DomainEventMiddleware($entityManager),
// Add other middleware (e.g., logging, validation)
)
);
return $bus;
});
}
@Command or @Event (if using SimpleBus annotations).use SimpleBus\MessageBus\Command\CommandHandler;
class CreateOrderHandler implements CommandHandler
{
public function handle(CreateOrder $command)
{
$order = new Order($command->details);
$entityManager->persist($order);
$entityManager->flush(); // Events are collected automatically
}
}
Route::post('/orders', function () {
$bus->dispatch(new CreateOrder($request->input()));
});
config/database.php with a connection (e.g., MySQL, PostgreSQL).Illuminate\Events unless explicitly bridged.EntityManager (e.g., connection pooling) may affect transaction behavior.How can I help you explore Laravel packages today?