Skip to content

Conversation

@sshekhar563
Copy link

Fixes #46369

This PR restores the caching and data-loading behavior that was lost when
the getInstance() methods were removed from the core classes.

Changes

  • FormFactory

    • Added static caching for form instances (private static array $forms)
    • Automatically loads XML form data (string or file)
    • Introduced clearCache() for tests/runtime reloads
  • UserFactory

    • Added static caching for user instances (private static array $cache)
    • Reuses cached users by ID or username to avoid duplicate DB queries
    • Introduced clearCache() for testing and runtime reloads

Benefits

  • Restores performance and behavior parity with the old Form::getInstance()
    and User::getInstance() implementations.
  • Prevents code duplication and performance regression.
  • Fully backward-compatible and consistent with Joomla 6 architecture.

Testing Instructions

  1. Call FormFactory::createForm() multiple times with the same name — ✅ should return the same instance.
  2. Call UserFactory::loadUserById() or loadUserByUsername() repeatedly — ✅ should only query DB once.
  3. Confirm no regressions occur in form handling or user loading.

…oomla#46369)

Signed-off-by: sshekhar563 <shekharsiddhant93@gmail.com>
@laoneo
Copy link
Member

laoneo commented Nov 7, 2025

Please create a new caching factory. This here is a bc break. That's why we intended interfaces to abstract different logic.

…e consistency

Implements caching and data loading to replace deprecated getInstance() behavior.
Code formatted to Joomla coding standards.

Signed-off-by: sshekhar563 <shekharsiddhant93@gmail.com>
Fixes joomla#46369

Signed-off-by: sshekhar563 <shekharsiddhant93@gmail.com>
@sshekhar563 sshekhar563 force-pushed the fix/getinstance-caching branch from 16725d9 to fe468e9 Compare November 8, 2025 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unresolved issues with removing getInstance() methods

3 participants