Change composer post-autoload-dump script to Artisan command #6647
+2
−1
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.
This is a suggestion to help solve an issue with the OpenTelemetry PHP SDK package but may also help other packages from falling into the same trap. There is an open issue here: open-telemetry/opentelemetry-php#1673
Laravel adds a PHP callback script to the post-autoload-dump event in composer.json
https://github.com/laravel/laravel/blob/12.x/composer.json#L36
https://getcomposer.org/doc/articles/scripts.md#scripts
When Composer runs PHP callback scripts it means you are inheriting all the dependencies of the composer.phar. This is not normally an issue if the script is fairly simple however the Laravel postAutoloadDump function calls the Composer autoload.php to load all dependencies necessary for Laravel to run. This means any packages that include any code in autoloaded files also gets run. In the case of the OpenTelemetry SDK it is instantiating a v3 Psr/Log/NullLogger instance in the autoload however Composer is using an older version of the Psr/Log package causing the script to fail.
If the intention is for the script to call Laravel with the correct dependencies it would make more sense to call it as an artisan command as this will create a dedicated PHP process and ensure the correct dependencies are being loaded for the command.
My suggested change is to swap the postAutoloadDump to use the
config:clear
andclear-compiled
commands as they are a direct replacement to the original script.I'm open to suggestions on a better command that would be more appropriate or if there are undesired consequences to this change. I initially tried
optimize:clear
however the tests failed as it assumes the cache layer exists using sqlite but the sqlite database doesn't exist unless you create a project instead so the command fails. Shouldoptimize:clear
fail if the cache layer is not available? Alternatively we could consider adding theconfig:clear
to theclear-compiled
command so we only have the one command to run?Thanks