Skip to content

fix(di): alias generated sulu.repository.* services to FQCN repositories - #10

Merged
manuxi merged 1 commit into
manuxi:3.xfrom
Buzkar:fix/persistence-repository-signatures
Jul 28, 2026
Merged

fix(di): alias generated sulu.repository.* services to FQCN repositories#10
manuxi merged 1 commit into
manuxi:3.xfrom
Buzkar:fix/persistence-repository-signatures

Conversation

@Buzkar

@Buzkar Buzkar commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #9.

Problem

configurePersistence() (Sulu's PersistenceExtensionTrait) generates sulu.repository.event, sulu.repository.event_dimension_content and sulu.repository.location definitions with (EntityManager, ClassMetadata) constructor arguments, while this bundle's repositories extend Doctrine's ServiceEntityRepository (ManagerRegistry constructor). Symfony's CheckTypeDeclarationsPass validates every definition, so bin/console lint:container fails 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 after configurePersistence().

Doing this in PHP (rather than in services.yaml) is deliberate: the YAML config is loaded before configurePersistence() runs, so a YAML alias would be silently overwritten by the trait's subsequent setDefinition() call. Within load(), ordering is guaranteed — no compiler pass needed.

Testing

  • New unit test tests/Unit/DependencyInjection/SuluEventExtensionTest.php asserts the three ids are public aliases pointing to the correct repository classes (i.e. no longer the broken definitions).
  • Full bundle test suite green: 171 tests, 452 assertions.
  • Verified in a real Sulu 3.x host project (bundle v3.1.5, doctrine/orm 3.6.7): with this patch applied, lint:container passes with exit 0 in all four environments (dev/test/stage/prod) without any app-level workaround.

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.
@manuxi

manuxi commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Hey @Buzkar, thank you for the pr, I'll take a look at it hopefully before of my vacation.

@manuxi
manuxi merged commit 1dbf890 into manuxi:3.x Jul 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lint:container fails: generated sulu.repository.* definitions use EntityManager args, repositories expect ManagerRegistry

2 participants