Files
FOSSBilling/src
Adam DaleyandClaude Sonnet 4.6 17b121ca51 fix(Servicedomain): require_once registrar adapter file before class_exists check (#3832)
* fix(Servicedomain): require_once registrar adapter file before class_exists check

Third-party registrar adapters uploaded after installation are absent from
Composer's static class map (generated with --optimize-autoloader), causing
class_exists() to return false even when the file is present on disk.

Mirror the pattern used by Payment adapters in ServicePayGateway: require_once
the adapter file when the class is not yet loaded, then re-check class_exists
to keep a clear error for adapters that define no class.

Fixes #3828

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mCNdqXfyuD2n1bjFK5zsv

* fix: require_once adapter/manager files before class_exists checks

Payment adapters, server managers, and the server_manager DI factory all
relied on Composer's classmap for dynamic class resolution. With
--optimize-autoloader the classmap is static, so third-party files dropped
into src/library/ after installation are invisible to class_exists().

AntLoader (removed in #3776) previously discovered these files on the fly;
this commit restores equivalent behaviour by requiring files explicitly:

- ServicePayGateway::getAdapterClassName() now checks both nested-dir and
  flat file formats before falling back, replacing the blind `include`
- Servicehosting/Service::getServerManagerConfig() require_onces the
  manager file before calling is_callable() so the class is guaranteed
  present; Server_ has no PSR-0 entry so this also fixes non-optimised builds
- di.php server_manager factory require_oncess the manager file when the
  class is absent from the classmap (adds Path import accordingly)

Registrar adapter loading was fixed separately in the prior commit.

Related to #3828

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mCNdqXfyuD2n1bjFK5zsv

* fix: address code-review findings on adapter/manager class loading

- Servicehosting getServerManagerConfig: wrap require_once in try/catch
  so a PHP parse error in a manager file returns [] instead of fataling
  the entire manager-list API call (restores old is_callable() behaviour)

- di.php server_manager factory: replace file_exists() with Symfony
  Filesystem::exists() per CLAUDE.md convention; extract the repeated
  ucfirst((string) $manager) call to a local $managerName variable; add
  Filesystem use-import alongside the existing Path import

- composer.json: add Server_ to the psr-0 autoload entries alongside
  Payment_ and Registrar_, giving server managers the same architectural
  treatment and making the require_once guards defensive fallbacks rather
  than the only load path

- ServicePayGateway getAdapterConfig: remove the redundant filesystem
  existence re-checks (lines 386-390) that duplicated what
  getAdapterClassName() just did; collapse into a single class_exists()
  guard with the user-facing :adapter placeholder message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mCNdqXfyuD2n1bjFK5zsv

* fix(tests): update ServicePayGateway tests to match refactored getAdapterConfig

After refactoring getAdapterConfig() to delegate filesystem lookups to
getAdapterClassName(), the tests were failing because:
- Three tests had atLeast()->once() expectations on filesystem->exists()
  that the method no longer calls directly
- One test expected an error message with the full class name, but the
  refactored code uses $pg->gateway (the gateway code) in the message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mCNdqXfyuD2n1bjFK5zsv

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 00:16:11 +02:00
..
2024-06-07 21:56:16 -07:00