Scenario: The user has an installed Magento Open Source or Adobe Commerce project and wants to upgrade to a new version. They call composer require-commerce <metapackage>
from the command line
- Composer boilerplate and plugin setup
- Composer sees the
"type": "composer-plugin"
value in the composer.json file for the plugin package - Composer reads the
"extra"->"class"
field to find the class that implements PluginInterface (PluginDefinition) PluginDefinition
implements Capable, telling Composer that it provides some capability (CommandProvider), which is supplied throughPluginDefinition::getCapabilities()
CommandProvider::getCommands()
supplies Composer with an instance of RequireCommerceCommand- Composer calls
RequireCommerceCommand::configure()
to obtain the command's name, description, options, and help textRequireCommerceCommand
extends Composer's native RequireCommand and adds its own values to those in the existing implementation
- Composer adds
RequireCommerceCommand
to the registry
- Composer sees the
- Composer recognizes
require-commerce
as the command passed to the executable and findsRequireCommerceCommand
as the command object registered under that name - Composer calls
RequireCommerceCommand::execute()
RequireCommerceCommand::execute()
backs up the user'scomposer.json
file through ExtendableRequireCommand::parseComposerJsonFile()RequireCommerceCommand::execute()
callsRequireCommerceCommand::runUpdate()
RequireCommerceCommand::runUpdate()
callsRequireCommerceCommand::parseMetapackageRequirement()
to check thecomposer require-commerce
arguments for amagento/product
ormagento/magento-cloud
metapackage- If a
magento/product
ormagento/magento-cloud
metapackage is found in the command arguments, it calls RootProjectUpdater::runUpdate() RootProjectUpdater::runUpdate()
calls DeltaResolver::resolveRootDeltas()DeltaResolver::resolveRootDeltas()
uses RootPackageRetriever to obtain the Composer Package objects for the rootcomposer.json
files from the default installation of the existing edition and version, the target edition and version supplied to thecomposer require-commerce
call, and the user's current installation including any customizations they have madeDeltaResolver::resolveRootDeltas()
iterates over the fields incomposer.json
to determine any values that need to be updated to match the root project'scomposer.json
file of the new Magento Open Source or Adobe Commerce edition/version- To find these values, it compares the values for each field in the default project for the installed edition/version with the project for the target edition/version (
DeltaResolver::findResolution()
) - If a value has changed in the target, it checks that field in the user's customized root
composer.json
file to see if it has been overwritten with a custom value - If the user customized the value, the conflict will be resolved according to the specified resolution strategy: use the expected project's value, use the user's custom value, or prompt the user to specify which value should be used
- If
resolveRootDeltas()
found values that need to change,RequireCommerceCommand::runUpdate()
callsRootProjectUpdater::writeUpdatedComposerJson()
to apply those changes RequireCommerceCommand::execute()
calls the nativeRequireCommand::execute()
function, which will now use the updated rootcomposer.json
file if the plugin made changes- If the
RequireCommand::execute()
call fails after the plugin makes changes,RequireCommerceCommand::execute()
callsExtendableRequireCommand::revertRootComposerFile()
to restore thecomposer.json
file to its original state