Skip to content

refactor(bootstrap): register the autoloader in the legacy bootstrap - #1981

Merged
JohnVillalovos merged 1 commit into
mainfrom
jlvillal/autoload
Nov 19, 2026
Merged

JohnVillalovos merged 1 commit into
mainfrom
jlvillal/autoload

Conversation

@JohnVillalovos

Copy link
Copy Markdown
Collaborator

The classes this bootstrap loads depend on Composer packages and on the PSR-4 classes in src/: SmartyPage extends a Smarty class and SmartyRenderer implements a namespaced interface. Most web entry points include the bootstrap without including vendor/autoload.php first.

That only worked because SmartyPage.php requires the autoloader itself and is included before the first class that needs it. Reordering the includes, or removing Smarty later, would have turned that into a fatal error on those entry points.

Require the autoloader at the top of the bootstrap, so the dependency is stated where it exists. Nothing changes for current requests.

The test loads the bootstrap in a separate PHP process without an autoloader, and checks that the autoloader is the first file the bootstrap includes.

Assisted-by: Claude:claude-fable-5-2

The classes this bootstrap loads depend on Composer packages and on
the PSR-4 classes in src/: SmartyPage extends a Smarty class and
SmartyRenderer implements a namespaced interface. Most web entry
points include the bootstrap without including vendor/autoload.php
first.

That only worked because SmartyPage.php requires the autoloader
itself and is included before the first class that needs it.
Reordering the includes, or removing Smarty later, would have turned
that into a fatal error on those entry points.

Require the autoloader at the top of the bootstrap, so the dependency
is stated where it exists. Nothing changes for current requests.

The test loads the bootstrap in a separate PHP process without an
autoloader, and checks that the autoloader is the first file the
bootstrap includes.

Assisted-by: Claude:claude-fable-5-2

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain, and the change includes focused regression coverage for Composer autoloader registration and bootstrap include order.

No open issues 🎉

What changed in this PR

This PR updates the legacy common bootstrap to register Composer’s autoloader before loading classes that depend on Composer packages and PSR-4 code, with subprocess regression coverage for bootstrap loading and include order.

Changes:

  • Register Composer’s autoloader at the beginning of lib/Common/namespace.php.
  • Add isolated-process tests that load the bootstrap without a pre-registered autoloader.
  • Verify the autoloader is included first and dependent classes load correctly.
File Description
tests/​lib/​Common/​NamespaceBootstrapTest.php Adds subprocess tests covering bootstrap loading without an existing autoloader and verifying include order.
lib/​Common/​namespace.php Registers Composer’s autoloader before loading the dependent legacy common classes.

Review effort: Lite

@JohnVillalovos
JohnVillalovos merged commit 1dd1078 into main Nov 19, 2026
16 checks passed
@JohnVillalovos
JohnVillalovos deleted the jlvillal/autoload branch November 19, 2026 02:58
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.

2 participants