Repository navigation
Map the PSR-4 autoloader to the OpenMage\ComposerPlugin namespace - #13
Open
kasper-agg wants to merge 1 commit into
Open
kasper-agg wants to merge 1 commit into
kasper-agg wants to merge 1 commit into
Conversation
The empty PSR-4 prefix ("": "src/") is a fallback for every class.
Without an authoritative classmap, Composer's autoloader then checks
vendor/openmage/composer-plugin/src/<Class>.php for every class it
doesn't know, which in OpenMage is every Magento class, on every request.
All classes in src/ are in the OpenMage\ComposerPlugin namespace, so map
only that prefix.
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
composer.jsonmaps the empty PSR-4 prefix tosrc/:An empty prefix is a fallback for every class. Unless a project uses an authoritative classmap (
classmap-authoritative), Composer's autoloader therefore checksvendor/openmage/composer-plugin/src/<Class>.phpfor every class it doesn't find in its classmap. In OpenMage that's every Magento class (app/code,lib/Varien, zf1), on every request. Composer's autoloader is registered beforeVarien_Autoload, so this lookup happens first, for each class.Traced on a stock OpenMage install (
strace -e trace=%file, loading five classes):One failed file lookup per class. PHP doesn't cache paths that don't exist, so each one reaches the filesystem.
All classes in
src/are in theOpenMage\ComposerPluginnamespace, so this PR maps only that prefix:Effect
vendor/openmage/composer-plugin/src/.class_exists()findsOpenMage\ComposerPlugin\Pluginand the copy plugins, and Composer still loads the plugin (composer -vvvshows "Loading plugin OpenMage\ComposerPlugin\Plugin").Plugin::getPlugins()derives class names from the files'namespacelines, and those are unchanged.classmap-authoritativesee no difference.OpenMage gets the benefit after a release of this package and a
composer update openmage/composer-plugin.Checks
composer phpunit:test: OK (50 tests, 50 assertions).composer phpstan: no errors.composer validate: valid. It only warns about the existing unbound*constraints forsymfony/filesystemandsymfony/finder.composer rector:testfails withUnknown named parameter $strictBooleans, also without this change..rector.phpuses a parameter that newer Rector versions (allowed by^2.1.2) no longer accept. This is unrelated to this PR, so I've left it alone.Context
Found while looking into failed file lookups in OpenMage's autoloading, see OpenMage/magento-lts#5722 and OpenMage/magento-lts#5787.