fix(di): alias generated sulu.repository.* services to FQCN repositories - #10
Merged
Merged
Conversation
PersistenceExtensionTrait::configurePersistence() unconditionally builds sulu.repository.event/.event_dimension_content/.location definitions with an (EntityManager, ClassMetadata) constructor signature. Our repositories extend Doctrine's ServiceEntityRepository, which requires a ManagerRegistry instead, so these generated definitions are invalid and make `bin/console lint:container` fail for every consuming project. The three ids are otherwise unreferenced dead code; alias them to the already correctly wired FQCN repository services right after configurePersistence() runs, so the alias replaces the broken generated Definition instead of being overwritten by it.
Owner
|
Hey @Buzkar, thank you for the pr, I'll take a look at it hopefully before of my vacation. |
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.
Fixes #9.
Problem
configurePersistence()(Sulu'sPersistenceExtensionTrait) generatessulu.repository.event,sulu.repository.event_dimension_contentandsulu.repository.locationdefinitions with(EntityManager, ClassMetadata)constructor arguments, while this bundle's repositories extend Doctrine'sServiceEntityRepository(ManagerRegistryconstructor). Symfony'sCheckTypeDeclarationsPassvalidates every definition, sobin/console lint:containerfails in any host project — even though these three generated services are never referenced for event/location objects anywhere in Sulu core.Fix
Replace the invalid generated definitions with public aliases to the bundle's autowired FQCN repository services, set in
SuluEventExtension::load()directly afterconfigurePersistence().Doing this in PHP (rather than in
services.yaml) is deliberate: the YAML config is loaded beforeconfigurePersistence()runs, so a YAML alias would be silently overwritten by the trait's subsequentsetDefinition()call. Withinload(), ordering is guaranteed — no compiler pass needed.Testing
tests/Unit/DependencyInjection/SuluEventExtensionTest.phpasserts the three ids are public aliases pointing to the correct repository classes (i.e. no longer the broken definitions).lint:containerpasses with exit 0 in all four environments (dev/test/stage/prod) without any app-level workaround.