Skip to content

feat: trigger autoloader_initialized event - #10590

Open
gilads-otiannoh24 wants to merge 2 commits into
codeigniter4:4.8from
gilads-otiannoh24:4.8
Open

gilads-otiannoh24 wants to merge 2 commits into
codeigniter4:4.8from
gilads-otiannoh24:4.8

Conversation

@gilads-otiannoh24

Copy link
Copy Markdown

Description

This PR introduces the autoloader_initialized event triggered immediately after the Autoloader finishes its
initialization 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_initialized event and passing the Autoloader instance:

  • Packages can dynamically register namespaces, classmaps, or helpers without requiring manual/cumbersome edits to the
    user's app/Config/Autoload.php.
  • Enables advanced package behavior, such as opinionated automatic module discovery and convention-based package
    bootstrapping.

Changes Made

  • Core: Added Events::trigger('autoloader_initialized', $this) at the end of CodeIgniter\Autoloader\Autoloader::initialize().
  • Tests: Added unit tests in tests/system/Autoloader/AutoloaderTest.php to verify the event is dispatched and receives the Autoloader instance.
  • Documentation:
  • Added documentation for autoloader_initialized under Event Points in user_guide_src/source/extending/events.rst.
  • Added changelog entry in the relevant changelog file.

Checklist

  • Target branch is correct (4.8 / feature branch)
  • GPG-signed commits
  • Code style checked (composer cs-fix / composer cs)
  • Unit tests added and passing
  • User guide and changelog updated

@carson-codeigniter4 carson-codeigniter4 Bot added 4.8 PRs that target the `4.8` branch. needs template Opened issues not following the bug form template labels Sep 26, 2026
@carson-codeigniter4

Copy link
Copy Markdown

Hi there, @gilads-otiannoh24! 👋

It looks like this pull request does not follow our template:

Please update the description to follow the template. The needs template label will be removed automatically once it does.


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
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

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.

Copilot review overview

🟡 Changes recommended

The trigger can fatally break Composer-free installations and the preload bootstrap path.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds an early autoloader lifecycle event for package extensions on the 4.8 branch.

Changes:

  • Triggers autoloader_initialized after 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.

Comment thread system/Autoloader/Autoloader.php Outdated
$this->loadComposerAutoloader($modules);
}

Events::trigger('autoloader_initialized', $this);
Comment on lines +409 to +425
$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);
@codeigniter4 codeigniter4 deleted a comment from carson-codeigniter4 Bot Sep 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. needs template Opened issues not following the bug form template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants