Skip to content

fix(database): link entity extenders at boot so companions hydrate during HTTP requests#74

Open
michalbiarda wants to merge 1 commit into
marko-php:developfrom
michalbiarda:feature/entity-extender-boot
Open

fix(database): link entity extenders at boot so companions hydrate during HTTP requests#74
michalbiarda wants to merge 1 commit into
marko-php:developfrom
michalbiarda:feature/entity-extender-boot

Conversation

@michalbiarda
Copy link
Copy Markdown

Summary

  • EntityMetadataFactory was not registered as a singleton — every resolution created a fresh instance with an empty cache
  • linkExtenders() was only called from SchemaRegistry::registerEntities(), which is invoked exclusively by CLI migration commands (DiffCommand, MigrateCommand)
  • During HTTP requests, $metadata->extenders was always [], so EntityHydrator never attached companion entities

Fix

  • Register EntityMetadataFactory as a singleton in module.php
  • Add a boot callback that discovers all entity classes across vendor, modules, and app, then calls linkExtendersFrom() to populate the extender map once at startup
  • linkExtendersFrom() throws a loud EntityException if an extender references a parent class that cannot be autoloaded, rather than silently ignoring the misconfiguration

Test plan

  • linkExtendersFrom scans entity classes and links extenders to their parents
  • linkExtendersFrom ignores entities without extends
  • linkExtendersFrom throws EntityException when an extender's parent class cannot be autoloaded
  • Full test suite passes: composer test

Closes #73

🤖 Generated with Claude Code

…ring HTTP requests

EntityMetadataFactory is now a singleton and a boot callback discovers all
entity classes and calls linkExtendersFrom() so extender metadata is populated
before any repository hydration occurs. Previously linkExtenders() was only
called from CLI migration commands, leaving companions unattached at runtime.

Closes marko-php#73

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the bug Something isn't working label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entity extender companions are never hydrated during HTTP requests

1 participant