[11.x] Preload base options for missing config files #51619
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Laravel 11 allows you to remove configuration files to keep your application slim and easier to maintain. However, Dries recently brought to my attention some issues which may arise when configuration files are removed.
After digging into the code, the issue occurs when a config file references another value from a missing (removed) config file. From one of the issues, Sanctum referencing
app.url
whenconfig/app.php
has been removed.This is because the application configuration files are loaded and merged with the base options, then any remaining base options are loaded.
This PR solves this issue by first loading the base options from any missing core configuration file first (i.e. app, broadcasting, view, etc). It is safe to preload these options as they do not exist and therefore do not need to be merged with user customizations.
There is no additional complexity as it loads the same amount of config files. It simply loops over any missing config files first to avoid invalid references. Furthermore, config may be cached, so this additional loop only runs once.
I did attempt to add a test for this, but it was pretty hacky as I needed to remove config files from the TestBench skeleton app for proper setup. Since that skeleton would also need to be maintained, it's not really worth it. If Orchestra ever adds a hook for swapping config files, I'll gladly backfill a test.