feat: trigger autoloader_initialized event - #10590
gilads-otiannoh24 wants to merge 2 commits into
Conversation
|
Hi there, @gilads-otiannoh24! 👋 It looks like this pull request does not follow our template:
Please update the description to follow the template. The Hi there, @gilads-otiannoh24! 👋 Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md |
ba948dc to
68b0214
Compare
68b0214 to
f9cc7c0
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The trigger can fatally break Composer-free installations and the preload bootstrap path.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds an early autoloader lifecycle event for package extensions on the 4.8 branch.
Changes:
- Triggers
autoloader_initializedafter namespace discovery. - Adds event tests and documentation.
- Records the feature in the 4.8 changelog.
| File | Description |
|---|---|
system/Autoloader/Autoloader.php |
Adds the event trigger. |
tests/system/Autoloader/AutoloaderTest.php |
Tests dispatch and argument identity. |
user_guide_src/source/extending/events.rst |
Documents the event point. |
user_guide_src/source/changelogs/v4.8.0.rst |
Adds the changelog entry. |
Validation was limited to static review; automated checks remain with CI.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| $this->loadComposerAutoloader($modules); | ||
| } | ||
|
|
||
| Events::trigger('autoloader_initialized', $this); |
| $triggered = false; | ||
| $passedLoader = null; | ||
|
|
||
| Events::on('autoloader_initialized', static function ($loader) use (&$triggered, &$passedLoader): void { | ||
| $triggered = true; | ||
| $passedLoader = $loader; | ||
| }); | ||
|
|
||
| $config = new Autoload(); | ||
| $modules = new Modules(); | ||
| $modules->discoverInComposer = false; | ||
|
|
||
| $loader = new Autoloader(); | ||
| $loader->initialize($config, $modules); | ||
|
|
||
| $this->assertTrue($triggered); | ||
| $this->assertSame($loader, $passedLoader); |


Description
This PR introduces the
autoloader_initializedevent triggered immediately after theAutoloaderfinishes itsinitialization and Composer namespace discovery.
Rationale
Currently, packages and third-party extensions do not have an early hook into the framework lifecycle to interact directly with the autoloader. By triggering the
autoloader_initializedevent and passing theAutoloaderinstance:user's
app/Config/Autoload.php.bootstrapping.
Changes Made
Events::trigger('autoloader_initialized', $this)at the end ofCodeIgniter\Autoloader\Autoloader::initialize().tests/system/Autoloader/AutoloaderTest.phpto verify the event is dispatched and receives theAutoloaderinstance.autoloader_initializedunder Event Points inuser_guide_src/source/extending/events.rst.Checklist
4.8/ feature branch)composer cs-fix/composer cs)