Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Composer PSR-4 overwrites Config\Autoload::$psr4 #5902

Merged
merged 1 commit into from
Apr 16, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Apr 15, 2022

Description
The user guide says:

If the same namespace is defined in both CodeIgniter and Composer, CodeIgniter’s autoloader will be the first one to get a chance to locate the file.
https://codeigniter4.github.io/CodeIgniter4/concepts/autoloader.html#composer-support

But if you move the app/ folder, the autoloader can't find Config\App.php only when Composer is enabled.
See https://forum.codeigniter.com/showthread.php?tid=81690

It is because the Composer's namespace paths overwrite the Config\Autoload::$psr4 settings.

$this->prefixes = array_merge($this->prefixes, $newPaths);

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one.
https://www.php.net/manual/en/function.array-merge.php#refsect1-function.array-merge-description

This PR fixes the bug.

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 15, 2022
@MGatner
Copy link
Member

MGatner commented Apr 16, 2022

@lonnieezell had some issues early on with using the CodeIgniter namespace in some packages (hence "Sparks"). I assume this won't affect those since they have subsequent parts (e.g. CodeIgniter\Tasks) but something to keep an eye on.

@kenjis kenjis merged commit fc6bb8e into codeigniter4:develop Apr 16, 2022
@kenjis kenjis deleted the fix-autoloader-psr4 branch April 16, 2022 12:46
@kenjis
Copy link
Member Author

kenjis commented Apr 16, 2022

@MGatner If you mean #5292, I fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants