feat: refactor Database to use Command messages instead of direct EntityManager#98
Merged
atournayre merged 5 commits intomainfrom Aug 6, 2025
Merged
Conversation
…ityManager - Replace EntityManagerInterface with CommandBusInterface in Database class - Add SyncCommandInterface for synchronous command execution - Create DatabasePersistCommand, DatabaseRemoveCommand, and DatabaseFlushCommand - Add corresponding handlers: DatabasePersistHandler, DatabaseRemoveHandler, DatabaseFlushHandler - Update Database methods to dispatch commands instead of direct EntityManager calls - Add handler interfaces following Elegant Object principles - Update PHPStan configuration to allow Handler suffix in persistence layer - Update documentation for database.md and domain-events.md - Fix unit tests to work with new command-based architecture This refactoring improves architecture by: - Separating concerns through command/handler pattern - Enabling better testability and mocking - Supporting future middleware and event handling - Maintaining backward compatibility of public API 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Apply Rector formatting corrections - Add missing semicolons on chained method calls - Fix parameter alignment in method signatures - Add missing newlines at end of files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Updated `DatabaseTrait::database()` to use `CommandBus` from dependency injection. - Adjusted `Database::new` instantiation to pass `CommandBus` instead of `EntityManager`.
…andling - Introduced `EntityDependencyInjection` type hint in `database()` method for clarity. - Refined assertions to ensure proper dependency injection availability. - Adjusted `Database::new` instantiation to use `commandBus()` method for compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the
Databaseclass to use Symfony's Command/Handler pattern instead of directly using Doctrine's EntityManager. This architectural change improves separation of concerns and testability while maintaining full backward compatibility.Key Changes
EntityManagerInterfacewithCommandBusInterfaceDatabasePersistCommandfor persist operationsDatabaseRemoveCommandfor remove operationsDatabaseFlushCommandfor flush operationsBenefits
Testing
Test plan
🤖 Generated with Claude Code